如何选择在C#中保存Excel文件的路径

时间:2018-11-12 07:33:52

标签: c# excel

但是我可以输入要保存的文件的名称,如何在要保存excel文件的路径中添加?

这是我使用的代码

JButton btnB = new JButton("white");
btnB.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        if (btnB.isSelected()) {
            panel2.setVisible(true);
        }

        if(!btnB.isSelected()) {

3 个答案:

答案 0 :(得分:0)

使用第一个参数,您不仅可以指定文件名,还可以指定位置。

示例:

wbook.SaveAs("c:\\file_path\\file_name",  Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

答案 1 :(得分:0)

在第一个参数中将路径添加到文件名:

ViewController

答案 2 :(得分:0)

只需结合您的文件路径和文件名即可。

xlWorkBook.SaveAs($@"c:\{Module.Text}" + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);