private void buttonExport_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fileToSavePath = folderBrowser.SelectedPath + "\\"; } excelDoc = new ExcelApplication(fileToExcel); excelDoc.GetValueToDictionary(1); wordDoc = new WordApplication(fileToWord); string[] labels = excelDoc.valuesDictionary[1]; foreach (KeyValuePair<int, string[]> item in excelDoc.valuesDictionary) { if (item.Key == 1) { labels = item.Value; } else { for (int i = 0; i < labels.Length; i++) { wordDoc.FindAndReplace(labels[i], item.Value[i]); } wordDoc.SaveDocument(fileToSavePath + (item.Key - 1).ToString(), wordDoc.SafeFileFormat(cBformatExp.SelectedItem.ToString())); wordDoc.CloseWordApp(); wordDoc = new WordApplication(fileToWord); } } }
private void buttonExport_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fileToSavePath = folderBrowser.SelectedPath + "\\"; } excelDoc = new ExcelApplication(fileToExcel); excelDoc.GetValueToDictionary(1); wordDoc = new WordApplication(fileToWord); string[] labels = excelDoc.valuesDictionary[1]; foreach (KeyValuePair <int, string[]> item in excelDoc.valuesDictionary) { if (item.Key == 1) { labels = item.Value; } else { for (int i = 0; i < labels.Length; i++) { wordDoc.FindAndReplace(labels[i], item.Value[i]); } wordDoc.SaveDocument(fileToSavePath + (item.Key - 1).ToString(), wordDoc.SafeFileFormat(cBformatExp.SelectedItem.ToString())); wordDoc.CloseWordApp(); wordDoc = new WordApplication(fileToWord); } } }