写入已打开的excel文件(通过openfiledialog) [英] Write to an already opened excel file (through openfiledialog)

查看:304
本文介绍了写入已打开的excel文件(通过openfiledialog)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello MSDN。 我是C#.NET开发的新手,我正在试图弄清楚如何将数据写入已由opefiledialog方法打开的工作簿中的特定工作表和单元格。 
有没有办法做到这一点? 
$


或者写入打开的excel文件的方法在打开excel文件后启动。不知道最好的方法是什么。



这是代码。


 private void selectHeatBalanceToolStripMenuItem_Click(object sender,EventArgs e)
{

using(OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory =" c:\\" ;;
openFileDialog.Filter =" xls files(* .xls)| * .xls | xlsx files(* .xlsx)| * .xlsx" ;;
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
工作簿wbook;
工作表wsheet;
_Application excel = new _Excel.Application();

if(openFileDialog.ShowDialog()== DialogResult.OK)
{
excel = new _Excel.Application();
wbook = excel.Workbooks.Open(openFileDialog.FileName);
excel.Visible = true;
}
}


}





解决方案

OpenFileDialog无法打开文件。它允许用户选择文件名。


有关如何操作Excel的文档对象模型,请访问https://social.msdn.microsoft.com/Forums/office/en -US /家?论坛= exceldev。


Hello MSDN.  I am new to C#.NET development and I am trying to figure out how to write data into specific sheets and cells in a workbook that is already opened by opefiledialog method.  Is there a way to do this? 

Alternatively the method that writes to the open excel file initiates after the excel file has been opened. Not sure what the best approach is here.

Here is the code.

private void selectHeatBalanceToolStripMenuItem_Click(object sender, EventArgs e)
        {

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter = "xls files (*.xls)|*.xls|xlsx files (*.xlsx)|*.xlsx";
                openFileDialog.FilterIndex = 2;
                openFileDialog.RestoreDirectory = true;
                Workbook wbook;
                Worksheet wsheet;
                _Application excel = new _Excel.Application();

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    excel = new _Excel.Application();
                    wbook = excel.Workbooks.Open(openFileDialog.FileName);
                    excel.Visible = true;
                }
            }

            
        }



解决方案

OpenFileDialog does not open files. It lets the user to pick a file name.

For how to manipulate Excel's Document Object Model, ask at https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev.


这篇关于写入已打开的excel文件(通过openfiledialog)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆