I have numeric that has problems in formatting due to Aspose's (or possibly Excel's) interpretation of the data as numeric or date format when the data is opened.
My data comes from a CSV file which I open using a stream. I've tried prepending various characters to the data but still seem to have an issue.
How can I get data in fields to appear 'as-is' with the text always being treated as text labels rather than dates or numerics?
Sample code which I'm using to open the data.
#region Private Data Members
private byte[] mData;
#endregion
#region Public Methods
///
/// Convert a CSV byte array to an Excel byte array
///
///
///
public byte[] CSVtoXLS(byte[] fileData)
{
License license = new License();
license.SetLicense("Aspose.Excel.lic");
// Write excel file using aspose open and save
Excel excel = new Excel();
MemoryStream memoryStream = new MemoryStream(fileData);
excel.Open(memoryStream, FileFormatType.CSV);
// Lock top row (freeze pane)
excel.Worksheets[0].FreezePanes(
1,1,1,
excel.Worksheets[0].Cells.MaxDataColumn);
for (int row=0; row<excel.Worksheets[0].Cells.MaxDataRow; row++)
{
// resize rows
excel.Worksheets[0].AutoFitRow(row);
}
for (int col=0; col<excel.Worksheets[0].Cells.MaxDataColumn; col++)
{
// resize columns
excel.Worksheets[0].AutoFitColumn(col);
}
MemoryStream memoryStream2 = new MemoryStream();
excel.Save(memoryStream2, FileFormatType.Excel97);
byte[] data = memoryStream2.ToArray();
// close and GC before exit
memoryStream.Close();
memoryStream2.Close();
excel = null;
memoryStream = null;
memoryStream2 = null;
return (data);
}
///
/// Convert a CSV stream to an Excel data stream
///
///
///
public System.IO.Stream CSVtoXLSStream(byte[] fileData)
{
License license = new License();
license.SetLicense("Aspose.Excel.lic");
// Write excel file using aspose open and save
Excel excel = new Excel();
MemoryStream memoryStream = new MemoryStream(fileData);
excel.Open(memoryStream, FileFormatType.CSV);
for (int row=0;
row<excel.Worksheets[0].Cells.MaxDataRow;
row++)
{
// resize rows
excel.Worksheets[0].AutoFitRow(row);
}
for (int col=0;
col<excel.Worksheets[0].Cells.MaxDataColumn;
col++)
{
// resize columns
excel.Worksheets[0].AutoFitColumn(col);
}
MemoryStream memoryStream2 = new MemoryStream();
excel.Save(memoryStream2, FileFormatType.Excel97);
return (memoryStream2);
}
#endregion