how to Convert XLSX (EXCEL) to XLS (EXCEL) without ms-office using c#

Posted by Naidulaxmi under C# on 1/17/2017 | Points: 10 | Views : 639 | Status : [Member] | Replies : 4
Hi Friends,

How to Convert XLSX (EXCEL) to XLS (EXCEL) with out ms-office using c#.Could you please give me one example .This is most urgent.

They want to convert this XLSX files to XLS. How to do that in C#, without Office on PC.

appalanaidu


Responses

Posted by: Susan2016 on: 1/17/2017 [Member] Starter | Points: 25

Up
0
Down
Use Spire.XLS with following code snippets
Workbook book = new Workbook();
book.LoadFromFile("sample.xlsx");
book.SaveToFile("result.xls", ExcelVersion.Version97to2003);


Naidulaxmi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naidulaxmi on: 1/17/2017 [Member] Starter | Points: 25

Up
0
Down
thanks for your replay Susan
Spire.XLS is not open source.
Can you please tell me any open source dll?



appalanaidu

Naidulaxmi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2H on: 1/17/2017 [Member] [MVP] Silver | Points: 25

Up
0
Down
You could make use of EPPlus Excel library. You can use first read the xlsx format file and then save the file as xls format using EpPlus Saveas method

EPPlus : http://epplus.codeplex.com/

Sample Code

//Read the xlsx format file
ExcelPackage package = new ExcelPackage(new FileInfo(@"c:\temp\New Microsoft Excel Worksheet.xlsx"));
DataTable tbl = ToDataTable(package);
using (ExcelPackage pck = new ExcelPackage())
{
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells["A1"].LoadFromDataTable(tbl, true);

//Write it back to the client as 2003 format
pck.SaveAs(new System.IO.FileInfo(@"c:\temp\Demo.xls"));

}


Code for ToDataTable Method


public DataTable ToDataTable(ExcelPackage package)
{
ExcelWorksheet workSheet = package.Workbook.Worksheets.First();
DataTable table = new DataTable();
foreach (var firstRowCell in workSheet.Cells[1, 1, 1, workSheet.Dimension.End.Column])
{
table.Columns.Add(firstRowCell.Text);
}

for (var rowNumber = 2; rowNumber <= workSheet.Dimension.End.Row; rowNumber++)
{
var row = workSheet.Cells[rowNumber, 1, rowNumber, workSheet.Dimension.End.Column];
var newRow = table.NewRow();
foreach (var cell in row)
{
newRow[cell.Start.Column - 1] = cell.Text;
}
table.Rows.Add(newRow);
}
return table;
}


Above code taken from : http://www.mikesdotnetting.com/article/277/reading-excel-files-without-saving-to-disk-in-asp-net

Thanks,
A2H
My Blog

Naidulaxmi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 1/19/2017 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://stackoverflow.com/questions/5852678/net-excel-library-that-can-read-write-xls-files

This is open source

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Naidulaxmi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response