Free Support Forum - aspose.com

Sometime reading cells gives garbage

I'm using aspose excel to extract the contents of an excel file. When i read through the cells in the worksheets I encounter that some of the reads gives me garbage instead of the values in the excel file.

I have created the following sample to show that two reads of the same excel file gives a different output. When I run this sample and compare the contents of the old output file with the contents of the new output file using windiff, they are different.

I'm currently only using a non registered version of aspose.excel version 3.5.3.0 - is the problem related to this?

I have attached the sample solution, including a sample excel file.

Best regards,

Tonny

FileStream excelstr = File.Open(@"..\..\test.xls",FileMode.Open);

byte[] excelbyte = new byte[excelstr.Length];

excelstr.Read(excelbyte,0,(int)excelstr.Length);

MemoryStream mstream = new MemoryStream(excelbyte);

Excel excel = new Excel();

excel.Open(mstream);

Aspose.Excel.Worksheet worksheet = excel.Worksheets["Ark1"];

DataSet dataset = new DataSet ();

DataTable table = dataset.Tables.Add();

table.Columns.Add("NAME");

table.Columns.Add("VALUE");

table.Columns.Add("BEMÆRKNING");

table.Columns.Add("BEMÆRK_2");

for (int i = 0;i < 53;i++)

{

string[] values = {worksheet.Cells[i,0].StringValue.Trim(),worksheet.Cells[i,1].StringValue.Trim(),worksheet.Cells[i,2].StringValue.Trim(),worksheet.Cells[i,3].StringValue.Trim()};

table.Rows.Add(values);

}

File.Copy(@"..\..\output.xml",@"..\..\oldoutput.xml",true);

dataset.WriteXml(@"..\..\output.xml");

This is an evaluation limitation. Please check http://www.aspose.com/wiki/default.aspx/Aspose.Excel/LicensingComponent.html and http://www.aspose.com/wiki/default.aspx/Aspose.Excel/GarbageTextInWorksheet.html .