04-12-2023
07:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-12-2023
07:46 AM
CONFIRM EXCEL WORKSHEET OVERWRITE ON PARTS LIST EXPORTING
I'm using the so known code to export parts lists to an excel workbook, and it's working as expected. However my template already has a worksheet named as the same name as the table name selected to export, and for my working procees, it has to be the same, The problem here is the Inventor warning asking for confirmation to overwrite the existing worksheet in the template, is there a way to answer "yes" via coding or just supress it?
See the code attached below:
'-------------Start of ilogic ------------------------------------------------ 'get the path and name of the drawing file 'ThisApplication.SilentOperation = True path_and_name = ThisDoc.PathAndFileName(False) ' without extension 'define oDoc oDoc = ThisDoc.Document 'specify the drawing sheet 'oSheet = oDoc.Sheets("Sheet:1") ' sheet by name oSheet = oDoc.Sheets(1) ' first sheet ' say there is a Partslist on the sheet. oPartslist = oSheet.PartsLists(1) ' create a new NameValueMap object oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'specify an existing template file 'to use For formatting colors, fonts, etc DESKTOP = System.Environment.GetFolderPath(Desktop) oOptions.Value("Template") = DESKTOP & "\TEMPLATE_ESTRUTURA.xlsx" 'specify the columns to export 'oOptions.Value("ExportedColumns") = "QTY;PART NUMBER;DESCRIPTION" 'specify the start cell oOptions.Value("StartingCell") = "A1" 'specify the XLS tab name 'here the file name is used oOptions.Value("TableName") = "LISTA MATERIAIS" 'ThisDoc.FileName(False) 'without extension 'choose to include the parts list title row 'in this example "Ye Old List of Parts" is written to the StartingCell oOptions.Value("IncludeTitle") = False 'choose to autofit the column width in the xls file oOptions.Value("AutoFitColumnWidth") = True oOptions.Value("OverwriteTable") = True ' export the Partslist to Excel with options oPartslist.Export(path_and_name & ".xlsx", _ PartsListFileFormatEnum.kMicrosoftExcel, oOptions) '-------------End of ilogic ------------------------------------------------