Dim NVP As NameValueMap
NVP = ThisApplication.TransientObjects.CreateNameValueMap
NVP.Add("TableName", "明细栏")
NVP.Add("ExportedColumns", "No.;Title;Techn. Details;Qty.;Unit;Bauteil Nummer;Supplier") '请检查输入与图纸完全一致标题,分号分隔
NVP.Add("IncludeTitle",True)
NVP.Add("StartingCell", "A3")
NVP.Add("Template", "C:\Path\to\your\Excel.xlsx") '填写excel模板文件名
NVP.Add("AutoFitColumnWidth",True)
FileName = ThisDoc.PathAndFileName(False) & ".xlsx"
If IO.File.Exists(FileName) Then Return
Dim oPartsList = ThisApplication.ActiveDocument.ActiveSheet.PartsLists(1)
oPartsList.Export(FileName,PartsListFileFormatEnum.kMicrosoftExcel,NVP)
Dim NVP As NameValueMap NVP = ThisApplication.TransientObjects.CreateNameValueMap NVP.Add("TableName", "明细栏") NVP.Add("ExportedColumns", "No.;Title;Techn. Details;Qty.;Unit;Bauteil Nummer;Supplier") '请检查输入与图纸完全一致标题,分号分隔 NVP.Add("IncludeTitle",True) NVP.Add("StartingCell", "A10") NVP.Add("Template", "E:\inventor\Excel\BOM.xlsx") '填写excel模板文件名 NVP.Add("AutoFitColumnWidth",True) FileName = ThisDoc.PathAndFileName(False) & ".xlsx" If IO.File.Exists(FileName) Then Return Dim oPartsList = ThisApplication.ActiveDocument.ActiveSheet.PartsLists(1) oPartsList.Export(FileName,PartsListFileFormatEnum.kMicrosoftExcel,NVP)
大佬,非常感谢你的回复!我根据你写的代码修改后,在iLogic中运行提示报错,参数如下:
参数错误。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))
不知是什么原因导致会出现这种问题呢。
Inventor不支持删除表头,但是可以用Excel操作删除这一行,更多功能你可以学习Excel API.比如设置边框线、格式等等
Dim NVP As NameValueMap
NVP = ThisApplication.TransientObjects.CreateNameValueMap
NVP.Add("TableName", "明细栏")
NVP.Add("ExportedColumns", "No.;Title;Techn. Details;Qty.;Unit;Bauteil Nummer;Supplier")
NVP.Add("IncludeTitle",True)
NVP.Add("StartingCell", "A3")
NVP.Add("Template", "C:\Path\to\your\Excel.xlsx")
NVP.Add("AutoFitColumnWidth",True)
FileName = ThisDoc.PathAndFileName(False) & ".xlsx"
If IO.File.Exists(FileName) Then Return
Dim oPartsList = ThisApplication.ActiveDocument.ActiveSheet.PartsLists(1)
oPartsList.Export(FileName, PartsListFileFormatEnum.kMicrosoftExcel, NVP)
ExcelApp = CreateObject("Excel.Application")
Excelbook = ExcelApp.Workbooks.Open(FileName)
Excelsheet = Excelbook.Worksheets(1)
Excelsheet.Range("A3").EntireRow.Delete()
Excelbook.Save
ExcelApp.Quit
,