Thanh toán phương pháp .SaveAs()
trong đối tượng Excel.
wbWorkbook.SaveAs("c:\yourdesiredFilename.csv", Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV)
Hoặc sau:
public static void SaveAs()
{
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook wbWorkbook = app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel.Sheets wsSheet = wbWorkbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet CurSheet = (Microsoft.Office.Interop.Excel.Worksheet)wsSheet[1];
Microsoft.Office.Interop.Excel.Range thisCell = (Microsoft.Office.Interop.Excel.Range)CurSheet.Cells[1, 1];
thisCell.Value2 = "This is a test.";
wbWorkbook.SaveAs(@"c:\one.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wbWorkbook.SaveAs(@"c:\two.csv", Microsoft.Office.Interop.Excel.XlFileFormat.xlCSVWindows, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wbWorkbook.Close(false, "", true);
}
Nguồn
2010-03-29 13:13:56
cảm ơn đối với sự giúp đỡ, nhưng làm thế nào tôi có thể chuyển đổi một tập tin hiện hành? – Gold
Trong trường hợp bạn vẫn còn thắc mắc, bạn sẽ cần mở tệp hiện có làm sổ làm việc đầu tiên bằng phương thức Excel.Application.Workbooks.Open() và sử dụng nó làm tham số wbWorkbook – markdigi
sử dụng xlSaveAsAccessMode.xlNoChange là đáng tin cậy hơn (cuộc gọi để SaveAs bị lỗi trong trường hợp của tôi nếu tôi sử dụng xlShared). – Benlitz