我想在vb.net的Excel表格中绑定'0' [英] I want to Bind '0' in Excel sheet from vb.net

查看:55
本文介绍了我想在vb.net的Excel表格中绑定'0'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我,我想从vb.net绑定Excel文件中的值0(例如; -00123)



  if  IsDBNull(DSResultset.Tables( 0 )。行(IRowCount).Item(  ChequeNo))然后 
lstchqNo =
其他
lstchqNo = DSResultset.Tables( 0 )。行(IRowCount).Item( ChequeNo
结束 如果

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





0'在excel

解决方案

中绑定时使用上面的代码截断了这个解决方案



  //  使用excel的命名空间file  
使用 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));
// 第一张excel文件
eWsheet =(excel.Worksheet) eWbook.Worksheets [ 1 ];
// 设置单元格的格式,现在可以在excel中保存像000123这样的值
eWsheet.get_Range( A4 A4)。NumberFormat = @ ;





vb.net代码



 ' 使用excel文件的命名空间 
Imports excel = Microsoft.Office.Interop.Excel

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

eWbook = CType ((eApp.Workbooks.Add( C:\ abc.xls )),excel.Workbook)
' 第一张excel文件
eWsheet = CType (eWbook.Worksheets( 1 ),excel.Worksheet)
' 设置单元格格式,现在可以在excel中保存000123等值
eWsheet .get_Range( A4 A4)。NumberFormat =


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

解决方案

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 = ""


这篇关于我想在vb.net的Excel表格中绑定'0'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆