Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Can any one help me, I want bind the value starting 0 (eg;-00123) in Excel file from vb.net

VB
if IsDBNull(DSResultset.Tables(0).Rows(IRowCount).Item("ChequeNo")) Then
    lstchqNo = ""                    
Else
   lstchqNo = DSResultset.Tables(0).Rows(IRowCount).Item("ChequeNo")
End If

sw.Write(lstchqNo)
sw.Write(vbTab)


0's are truncated by using above code while binding in excel
Posted
Updated 5-Dec-12 0:00am
v2
Comments
ZurdoDev 5-Dec-12 10:04am    
Format the cell as text first or add ' to the beginning of your string which tells Excel to treat it as text.

1 solution

check this solution

C#
//namespace for use excel file            
using excel = Microsoft.Office.Interop.Excel;

excel.Application eApp = new excel.Application();
excel.Worksheet eWsheet = new excel.Worksheet();
excel.Workbook eWbook;

eWbook = (excel.Workbook)(eApp.Workbooks.Add(@"C:\abc.xls"));
//first sheet of excel file
eWsheet = (excel.Worksheet)eWbook.Worksheets[1];
//set the format of cell, now you can save values like 000123 in excel
eWsheet.get_Range("A4", "A4").NumberFormat = "@";


code in vb.net

VB
'namespace for use excel file
Imports excel = Microsoft.Office.Interop.Excel

Dim eApp As excel.Application =  New excel.Application()
Dim eWsheet As excel.Worksheet =  New excel.Worksheet()
Dim eWbook As excel.Workbook

eWbook = CType((eApp.Workbooks.Add("C:\abc.xls")), excel.Workbook)
'first sheet of excel file
eWsheet = CType(eWbook.Worksheets(1), excel.Worksheet)
'set the format of cell, now you can save values like 000123 in excel
eWsheet.get_Range("A4", "A4").NumberFormat = ""
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900