[英]How to Create/Open Excel files using OpenXml with C#
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. 我有一个控制台应用程序,我们在其中使用OPENXML创建xlsx文件,我们能够创建xlsx文件并将其保存到应用程序中的特定文件夹中。
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. 然后,我们可以指定一个特定的路径来保存/打开现有文件。
I am new to this OpenXml, Can anyone please help me on this to proceed further? 我是这个OpenXml的新手,有人可以帮助我进一步进行此操作吗? How can I acheive this? 我该如何实现? Do we have any built-in DLL for this? 我们为此有任何内置的DLL吗?
Thanks. 谢谢。
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. 之后,您可以使用saveFileDialog.FileName.ToString()
属性获取完整路径。 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;
}
}
}
Ref: http://msdn.microsoft.com/en-us//library/system.windows.forms.savefiledialog.aspx 参考: http : //msdn.microsoft.com/en-us//library/system.windows.forms.savefiledialog.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.