Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Excel VB.NET
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 23:45pm
Edited 5-Dec-12 1:00am
v2
Comments
ryanb31 at 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
0 Sergey Alexandrovich Kryukov 6,434
1 OriginalGriff 6,178
2 Peter Leow 2,534
3 Abhinav S 2,274
4 Maciej Los 2,268


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2015
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