コード例 #1
0
ファイル: FormMain.cs プロジェクト: Homecoming07/Word-Excel
        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);
                }
            }
        }
コード例 #2
0
        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);
                }
            }
        }