private void addFileToolStripMenuItem_Click(object sender, EventArgs e) { _frmNewFile newFile = new _frmNewFile(); newFile.Text = _treeViewProjectExplore.SelectedNode.Text + " - " + newFile.Text; newFile.ShowDialog(); Excel.Application xlApp = default(Excel.Application); Excel.Workbook xlWorkBook = default(Excel.Workbook); //TabPage sheetPage = new TabPage(_treeViewProjectExplore.SelectedNode.Text); //Excel.Worksheet xlWorkSheet = default(Excel.Worksheet); Excel.Worksheet xlWorkSheet = new Excel.Worksheet(); TreeNode treeNode = new TreeNode(); treeNode.Text = newFile.textBoxName.Text + "." + newFile.comboBoxType.Text; treeNode.Tag = treeNode.Text; treeNode.Name = "File"; treeNode.ImageIndex = newFile.comboBoxType.SelectedIndex; newFile.Close(); if (newFile.textBoxName.Text != "") { _treeViewProjectExplore.SelectedNode.Nodes.Add(treeNode); _treeViewProjectExplore.SelectedNode.ExpandAll(); string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.SelectedNode.Tag + @"\" + treeNode.Tag; try { object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } finally { if (xlApp != null) { releaseObject(xlApp); } if (xlWorkBook != null) { releaseObject(xlWorkBook); } if (xlWorkSheet != null) { releaseObject(xlWorkSheet); } } if (System.IO.File.Exists(fName)) { doc = CompoundDocument.Open(fName); } } }
private void addFileToolStripMenuItem_Click(object sender, EventArgs e) { _frmNewFile newFile = new _frmNewFile(); newFile.ShowDialog(); Excel.Application xlApp = default(Excel.Application); Excel.Workbook xlWorkBook = default(Excel.Workbook); Excel.Worksheet xlWorkSheet = default(Excel.Worksheet); TreeNode treeNode = new TreeNode(); treeNode.Text = newFile.textBoxName.Text + "." + newFile.comboBoxType.Text; treeNode.Tag = treeNode.Text; treeNode.Name = "File"; treeNode.ImageIndex = newFile.comboBoxType.SelectedIndex; newFile.Close(); if (newFile.textBoxName.Text != "") { _treeViewProjectExplore.SelectedNode.Nodes.Add(treeNode); _treeViewProjectExplore.SelectedNode.ExpandAll(); string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.SelectedNode.Tag + @"\" + treeNode.Tag; try { object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } finally { if (xlApp != null) releaseObject(xlApp); if (xlWorkBook != null) releaseObject(xlWorkBook); if (xlWorkSheet != null) releaseObject(xlWorkSheet); } if (System.IO.File.Exists(fName)) { //if (System.Windows.Forms.MessageBox.Show("Would you like to open the excel file?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) //{ // try // { // //System.Diagnostics.Process.Start(fName); doc = CompoundDocument.Open(fName); // LoadExcel(); // } // catch (Exception ex) // { // System.Windows.Forms.MessageBox.Show("Error opening the excel file." + Environment.NewLine + // ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} //doc1 = CompoundDocument.Open(fName); } } }
private void addFileToolStripMenuItem_Click(object sender, EventArgs e) { _frmNewFile newFile = new _frmNewFile(); newFile.Text = _treeViewProjectExplore.SelectedNode.Text + " - " + newFile.Text; newFile.ShowDialog(); Excel.Application xlApp = default(Excel.Application); Excel.Workbook xlWorkBook = default(Excel.Workbook); //TabPage sheetPage = new TabPage(_treeViewProjectExplore.SelectedNode.Text); //Excel.Worksheet xlWorkSheet = default(Excel.Worksheet); Excel.Worksheet xlWorkSheet = new Excel.Worksheet(); TreeNode treeNode = new TreeNode(); treeNode.Text = newFile.textBoxName.Text + "." + newFile.comboBoxType.Text; treeNode.Tag = treeNode.Text; treeNode.Name = "File"; treeNode.ImageIndex = newFile.comboBoxType.SelectedIndex; newFile.Close(); if (newFile.textBoxName.Text != "") { _treeViewProjectExplore.SelectedNode.Nodes.Add(treeNode); _treeViewProjectExplore.SelectedNode.ExpandAll(); string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.SelectedNode.Tag + @"\" + treeNode.Tag; try { object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } finally { if (xlApp != null) releaseObject(xlApp); if (xlWorkBook != null) releaseObject(xlWorkBook); if (xlWorkSheet != null) releaseObject(xlWorkSheet); } if (System.IO.File.Exists(fName)) { doc = CompoundDocument.Open(fName); } } }
private void addFileToolStripMenuItem_Click(object sender, EventArgs e) { _frmNewFile newFile = new _frmNewFile(); newFile.ShowDialog(); Excel.Application xlApp = default(Excel.Application); Excel.Workbook xlWorkBook = default(Excel.Workbook); Excel.Worksheet xlWorkSheet = default(Excel.Worksheet); TreeNode treeNode = new TreeNode(); treeNode.Text = newFile.textBoxName.Text + "." + newFile.comboBoxType.Text; treeNode.Tag = treeNode.Text; treeNode.Name = "File"; treeNode.ImageIndex = newFile.comboBoxType.SelectedIndex; newFile.Close(); if (newFile.textBoxName.Text != "") { _treeViewProjectExplore.SelectedNode.Nodes.Add(treeNode); _treeViewProjectExplore.SelectedNode.ExpandAll(); string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.SelectedNode.Tag + @"\" + treeNode.Tag; try { object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } finally { if (xlApp != null) { releaseObject(xlApp); } if (xlWorkBook != null) { releaseObject(xlWorkBook); } if (xlWorkSheet != null) { releaseObject(xlWorkSheet); } } if (System.IO.File.Exists(fName)) { //if (System.Windows.Forms.MessageBox.Show("Would you like to open the excel file?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) //{ // try // { // //System.Diagnostics.Process.Start(fName); doc = CompoundDocument.Open(fName); // LoadExcel(); // } // catch (Exception ex) // { // System.Windows.Forms.MessageBox.Show("Error opening the excel file." + Environment.NewLine + // ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} //doc1 = CompoundDocument.Open(fName); } } }