如何将Excel工作簿保存到磁盘?

时间:2012-08-20 17:09:42

标签: excel file-io save office-interop

我正在动态创建一个在创建时显示给用户的Excel文件,但是我现在还需要将文件保存到服务器上。

如何将其保存到特定文件夹?

我有以下代码

public void ExportMembers()
    {

        Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();

        Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);

        Worksheet ws = (Worksheet)xla.ActiveSheet;

        ws.Cells[1, 1] = "Site Id";

       //I create the rest of the cells here

        xla.Visible = true; //this displays the excel spreadsheet to the user

        //client id code is here

                if (!System.IO.Directory.Exists("/Files/" + clientId + "/Excel"))
        { //if doesn't exist make folder

            System.IO.Directory.CreateDirectory("/Files/" + clientId);

            System.IO.Directory.CreateDirectory("/Files/" + clientId + "/Excel");

        }

 //save the xla as a file Here

    }

如何在服务器上保存电子表格?

感谢任何帮助。

由于

1 个答案:

答案 0 :(得分:1)

请参阅Microsoft.Office.Interop.Excel.Application

的Save方法

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.save