Click here to Skip to main content
13,150,622 members (43,009 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Can any one help me, I want bind the value starting 0 (eg;-00123) in Excel file from vb.net

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 4-Dec-12 22:45pm
Updated 5-Dec-12 0:00am
v2
Comments
ryanb31 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

check this solution

//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

'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 = ""
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.170924.2 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100