Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a server that can't have any office installed on it, so I'm using ClosedXML to do some manipulations on excel files. But ClosedXML only works on .xlsx file and I also have xls file to handle. I spend almost a full day searching for a way to convert .xls files to .xlsx files without using any office libraries (since there is no office installed on my designated server...)

Can someone PLEASE tell me how can I convert these .xls files to .xlsx files ? I can't use Microsoft.Office.Interop because it requires having office installed on the server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
977 views
Welcome To Ask or Share your Answers For Others

1 Answer

For Microsoft.Office.Interop you need to have office installed.

You could use OleDb to read it(f.e. into a DataTable). Then use a library like EPPlus or OpenXml to write the xlsx file. Both don't need to have office installed.

Creating an xlsx file from a DataTable with EPPLus is easy:

using (ExcelPackage pck = new ExcelPackage(newFile))
{
  ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Name of Worksheet");
  ws.Cells["A1"].LoadFromDataTable(dataTable, true);
  pck.Save();
}

The first link above shows how to get a DataTable from an xls-file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...