How to convert xlsx files into 2003 xls files programatically in C#?

前端 未结 4 1720
遥遥无期
遥遥无期 2021-01-03 12:39

I\'ve found ExcelPackage, a better library than Excel Interop API to create and mantain programatically excel sheets, but they are generated in .xlsx. Most of people that wi

4条回答
  •  遥遥无期
    2021-01-03 13:34

    Here is a piece of code from my project with IBM iSeries. It will convert ANY Excel file to Excel 2003:

    string MOVE_DOWNLOADED(string FILENAME)
    {
      string Path = FILENAME;
      Microsoft.Office.Interop.Excel.ApplicationClass app = new Microsoft.Office.Interop.Excel.ApplicationClass();           
      Microsoft.Office.Interop.Excel.Workbook workBook = app.Workbooks.Open(Path,
        0,
        true,
        5,
        "",
        "",
        true,
        Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
        "\t",
        false,
        false,
        0,
        true,
        1,
        0);
    
      string retval = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "_tmp_" + ".xlsx";
    
      try
      {
        workBook.SaveAs(retval, 
          Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795, 
          null, 
          null, 
          false, 
          false, 
          Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, 
          false, 
          false,
          null,
          null,
          null);
      }
      catch (Exception E)
      {
        MessageBox.Show(E.Message);
      }
    
      workBook.Close(null, null, null);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
      workBook = null;
      GC.Collect(); // force final cleanup!
    
      return retval;    
    }
    

提交回复
热议问题