Excel Interop w / VB.NET [英] Excel Interop w/ VB.NET
问题描述
下午好人 -
我在Excel Interop中完成一些特定功能时遇到了困难。 我可以使用.OpenText成功打开文本文件,但无法完成以下任务:问题#2很关键。 我正在使用VS2013,Framework 4.0或4.5,
和Excel 2013与互操作性库v15.0加载
1. 将字段自动调整为最大尺寸
2. 字段类型定义为"文本"为了防止领导Zero的被撤销,我已经阅读了无数的论坛和谷歌搜索结果,但没有任何作用,我仍然在失去我的领先零点。 我正在使用当前流程的代码如下所示,我们非常感谢任何有关字段格式化的帮助。
Dim excelapp作为新的Microsoft.Office.Interop.Excel .Application
Dim Filename As String = file2convert
Dim Origin As Object = Excel.XlPlatform.xlWindows
Dim StartRow As Object = 1
Dim DataType As Object = Excel.XlTextParsingType.xlDelimited
Dim TextQualifier As Object
Dim ConsecutiveDelimiter As Object = False
Dim Tab As As作为对象
Dim Seumolon As Object
Dim Comma As Object
Dim Space As Object
Dim Other As Object = FUE
Dim OtherChar As Object = False
excelapp.Workbooks.OpenText(文件名, Origin,StartRow,DataType,TextQualifier,ConsecutiveDelimiter,Tab,Semicolon,Comma,Space,Other,OtherChar)
excelapp.displayalerts = False
excelapp.ActiveWorkbook.SaveAs(文件名:=新file,FileFormat:= 51)
excelapp.ActiveWorkbook.Close(SaveChanges:= True)
excelapp.DisplayAlerts = True
excelapp.Quit ()
excelapp =无结果
--BCCGeorge
I am having difficulty accomplishing a few specific features within Excel Interop. I can successfully open a text file using .OpenText but can't get the following things to occur - issue #2 is critical. I am using VS2013, Framework 4.0 or 4.5,
and Excel 2013 with Interoperability Libraries v15.0 loaded
1. Autosize Fields to maximum size
2. Field Type to be defined as "Text" to prevent leading Zero's from being dropped
I've read countless forums and google results but nothing works, I'm still loosing my leading zero's. The code I'm using for the current process is below and any help for field formatting would be greatly appreciated.
Dim excelapp As New Microsoft.Office.Interop.Excel.Application
Dim Filename As String = file2convert
Dim Origin As Object = Excel.XlPlatform.xlWindows
Dim StartRow As Object = 1
Dim DataType As Object = Excel.XlTextParsingType.xlDelimited
Dim TextQualifier As Object
Dim ConsecutiveDelimiter As Object = False
Dim Tab As Object
Dim Semicolon As Object
Dim Comma As Object
Dim Space As Object
Dim Other As Object = False
Dim OtherChar As Object = False
excelapp.Workbooks.OpenText(Filename, Origin, StartRow, DataType, TextQualifier, ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar)
excelapp.displayalerts = False
excelapp.ActiveWorkbook.SaveAs(Filename:=newfile, FileFormat:=51)
excelapp.ActiveWorkbook.Close(SaveChanges:=True)
excelapp.DisplayAlerts = True
excelapp.Quit()
excelapp = Nothing
--BCCGeorge
推荐答案
CLR只是在这里将代码JIT到机器代码中。再次询问
Excel开发论坛 as您要求Excel实现其COM API。
CLR is just JITting your code into machine code here. Ask again in the Excel Development forum as you are asking Excel's implementation of its COM APIs.
这篇关于Excel Interop w / VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!