We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

CSV Leading zeros are stripped

I am having issues getting a few cells to display in text format for a csv

I have seen in excel you can do '00001 or =“00000” to preserve the leading zeros. I have seen using the ConvertNumericData = false will help But I had no luck. I am using v8 of aspose

Here is my code
Workbook workbook = new Workbook();
workbook.Settings.Region = Aspose.Cells.CountryCode.USA;
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Name = “Data”;

ImportTableOptions tableOptions = new ImportTableOptions();
tableOptions.ConvertNumericData = false;

//worksheet.Cells.ImportCustomObjects(this.GLList, 0, 0, tableOptions);
worksheet.Cells.ImportCustomObjects(this.GLList, clmAry, true, 0, 0, ((System.Collections.ICollection)this.GLList).Count, true, “MM/dd/yyyy”, false);

string sourceData = “=Data!A1:AN” + this.GLList.Count.ToString();
Aspose.Cells.Style style = new Aspose.Cells.Style();

workbook.Save(sPath, SaveFormat.CSV);

I dont feel this is the perfect solution, but I was able to get the results I wanted. Basically formatted the column with string.Format("=\"{0}\"", content.account_no)); But I had to interate through the rows

int curretCol = System.Array.FindIndex(clmAry, (string r) => r.ToString() == "account_no");
int currentrow = 1;
foreach (GLSearchDC content in GLList)
Cell cell = worksheet.Cells[CellsHelper.CellIndexToName(currentrow++, curretCol)];
cell.PutValue(string.Format("=\"{0}\"", content.Account_No));


Thanks for your posting and considering Aspose.Cells.

We think, the solution suggested by you is a good solution because CSV is just a simple text format that does not have styles settings which can be used to show the leading 0s.

Also, in csv leading 0s are preserved but when you view in Microsoft Excel, it does not show leading 0s because it deals with more complex formats like xls or xlsx etc.

However, if you open your csv file in notepad, you will see leading 0s are present there.