LoginSignup
11
10

More than 5 years have passed since last update.

c#で.xlsから.xlsxへ変換する

Posted at

[参考サイト]
http://convertxsltoxlsx.blogspot.jp

.xlsファイルを開く→.xlsx形式で保存→.xlsファイルを削除。
参照マネージャー→COM→Microsoft Excel 14.0 Object Libraryの設定も忘れずに。

sample.cs
static void convertSample()
{
    string xlsFileName = @"d:\SampleReportExcel.xls";
    string xlsxFileName = @"d:\SampleReportExcel.xlsx";

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

    // .xlsファイルを開く。
    Microsoft.Office.Interop.Excel.Workbook eWorkbook = excelApp.Workbooks.Open(xlsFileName);

    // .xlsx形式で保存する。
    eWorkbook.SaveAs(xlsxFileName,
        Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing,
        Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing);

    // ファイルを閉じる
    eWorkbook.Close(false, Type.Missing, Type.Missing);

    // .xlsファイルを削除する。
    File.Delete(xlsFileName);
}

11
10
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10