生成Excel文件的动态路径 [英] Dynamic path to generated Excel File
问题描述
朋友们,
i使用下面给出的代码生成excel文件,但它在c:\\驱动器中生成文件,但我想要更改文件生成位置,以便如何更改生成文件的位置我使用下面给出的代码。
Microsoft.Office.Interop.Excel.Application xlApp ;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop。 Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks .Add(misValue);
xlWorkSheet =(Microsoft.Office.Interop.Excel.Worksheet )xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells [1,1] =c:\\ \\\csharp-Excel.xls;
xlWorkBook.SaveAs(c:\\ \\\csharp-Excel.xls,Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,misValue,misValue,misValue,misValue,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,misValue,misValue,misValue,misValue, misValue);
xlWorkBook.Close(true,misValue,misValue);
xlApp.Quit( );
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
hi friends,
i generate excel file using code given below but it''s generate file in "c:\\" drive but i want to change location of file where it was generated so how can i change location where file is generated i use code given below.
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "c:\\csharp-Excel.xls";
xlWorkBook.SaveAs("c:\\csharp-Excel.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
推荐答案
xlWorkBook。 SaveAs( c:\\\\ [[[[[[[[[[[[[[[[$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
需要改变路径。
xlWorkBook.SaveAs("c:\\csharp-Excel.xls",
YOU are telling excel where to save the workbook, YOU need to change the path.
这篇关于生成Excel文件的动态路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!