How to get zero values while importing datatables to excel sheet

Posted by Janrose under C# on 3/12/2015 | Points: 10 | Views : 394 | Status : [Member] | Replies : 1
We are developing an automation tool in c#, we are using datatables and importing that datatables into excel sheet, while importing the values like "0056" we are finding difficulties here, becoz in excel sheet(output sheet) it was printing only "56" instead of "0056".

Please provide any solution for this...


Posted by: Yesi on: 3/29/2015 [Member] Starter | Points: 25

If your original data is 0056 you can try this .NET API , and it can keep your original data format.
Code here:
private void button1_Click(object sender, EventArgs e)

//connect database
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString @"Provider=""Microsoft.Jet.OLEDB.4.0"";Data Source=""demo.mdb"";User Id=;Password="
OleDbCommand command = new OleDbCommand();
command.CommandText = "select * from parts";
DataSet dataSet = new System.Data.DataSet();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command.CommandText,connection);
DataTable t = dataSet.Tables[0];
//export datatable to excel
Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.InsertDataTable(t, true, 1, 1);

Tutorials here: .

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

Login to post response