TheFjallraven
TheFjallraven
CC#
Created by TheFjallraven on 6/25/2023 in #help
❔ Add textbox.text from Form1 to another class
12 replies
CC#
Created by TheFjallraven on 6/25/2023 in #help
❔ Add textbox.text from Form1 to another class
12 replies
CC#
Created by TheFjallraven on 6/25/2023 in #help
❔ Add textbox.text from Form1 to another class
namespace BlankiDoc___Lekari { class WordHelper {
private FileInfo _fileInfo;
public WordHelper(string fileName) {
if (File.Exists(fileName)) { _fileInfo = new FileInfo(fileName); } else { throw new ArgumentException("File not found"); } }
internal bool Process(Dictionary<string, string> items) { Word.Application app = null; try { app = new Word.Application(); Object file = _fileInfo.FullName;
Object missing = Type.Missing;
app.Documents.Open(file); foreach (var item in items) { Word.Find find = app.Selection.Find; find.Text = item.Key; find.Replacement.Text = item.Value; Object wrap = Word.WdFindWrap.wdFindContinue; Object replace = Word.WdReplace.wdReplaceAll; find.Execute(FindText: Type.Missing, MatchCase: false, MatchWholeWord: false, MatchWildcards: false, MatchSoundsLike: missing, MatchAllWordForms: false, Forward: true, Wrap: wrap, Format: false, ReplaceWith: missing, Replace: replace);
} Object newFileName = Path.Combine(_fileInfo.DirectoryName, "docs", _fileInfo.Name + DateTime.Now.ToString("ddMMyy")); app.ActiveDocument.SaveAs2(newFileName); app.ActiveDocument.Close(); MessageBox.Show("Документът : " + newFileName + " е успешно създаден.");

return true; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (app != null) { app.Quit(); } } return false;

} } }
12 replies
CC#
Created by TheFjallraven on 6/25/2023 in #help
❔ Add textbox.text from Form1 to another class
the textbox9 seems to be public
12 replies
CC#
Created by TheFjallraven on 6/25/2023 in #help
❔ Add textbox.text from Form1 to another class
Object newFileName = Path.Combine(_fileInfo.DirectoryName, "docs", _fileInfo.Name + DateTime.Now.ToString("ddMMyy"));
12 replies
CC#
Created by TheFjallraven on 6/25/2023 in #help
❔ Add textbox.text from Form1 to another class
public System.Windows.Forms.TextBox textBox9;
12 replies