如何在C#中使用OpenXml创建/打开Excel文件 [英] How to Create/Open Excel files using OpenXml with C#
问题描述
我有一个控制台应用程序,我们在其中使用OPENXML创建xlsx文件,我们能够创建xlsx文件&将其保存到应用程序中的特定文件夹中.
I have a console application in which we are creating xlsx files using OPENXML, we are able to create xlsx file & save it into specific folder in application.
但是现在我们要显示该文件,并弹出一个保存/打开"对话框.然后,我们可以指定一个特定的路径来保存/打开现有文件.
But Now we want to show that file as a Save/Open dialog pop up. Then we can able to specify a particular path to save/ to open the existing files.
我是这个OpenXml的新手,有人可以帮助我进一步进行此操作吗?我怎样才能做到这一点?我们有内置的DLL吗?
I am new to this OpenXml, Can anyone please help me on this to proceed further? How can I acheive this? Do we have any built-in DLL for this?
谢谢.
推荐答案
保存文件对话框.它将提示用户选择保存文件的位置.之后,您可以使用saveFileDialog.FileName.ToString()
属性获取完整路径.
请参见下面的示例代码:
se the Save file dialog. It will prompts the user to select a location for saving a file. After that you can use saveFileDialog.FileName.ToString()
property to get the full path.
See the sample code below:
//Save a file in a particular format as specified in the saveAsType parameter
private void OpenSaveFileDialog(int saveAsType)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments);
saveFileDialog.Filter = "CSV|*.csv|Excel|*.xlsx";
saveFileDialog.FilterIndex = saveAsType;
saveFileDialog.Title = "Save Data";
saveFileDialog.FileName = "My File";
saveFileDialog.ShowDialog();
if (saveFileDialog.FileName != "")
{
//File Path = m_fileName
m_fileName = saveFileDialog.FileName.ToString();
//FilterIndex property is one-based.
switch (saveFileDialog.FilterIndex)
{
case 1:
m_fileType = 1;
break;
case 2:
m_fileType = 2;
break;
}
}
}
参考: http://msdn.microsoft .com/en-us//library/system.windows.forms.savefiledialog.aspx
这篇关于如何在C#中使用OpenXml创建/打开Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!