Keeping it as simple as possible, this Job will write to an existing Excel sheet. Filename in variable fileName Row to write data to in variable excelRow static void RSH003_AppendExcel(Args _args) { // Variables for Dialog FileName fileName = @'C:\Test.xlsx'; // Variabler til Excel SysExcelApplication sysExcelApplication; SysExcelWorksheet sysExcelWorksheet; SysExcelWorksheets sysExcelWorksheets; SysExcelWorkbooks sysExcelWorkbooks; SysExcelWorkbook sysExcelWorkbook; SysExcelCell sysExcelCell; counter excelRow; // Open the Excel document sysExcelApplication = SysExcelApplication::construct(); sysExcelWorkbooks = sysExcelApplication.workbooks(); //specify the file path that you want to read try { sysExcelWorkbooks.open(filename,0,false); } catch (Exception::Error) { throw error("File cannot be opened."); } sysExcelWorkbook = sysExcelWorkbooks.item(1); sysExcelWorksheets = sysExcelWorkbook.worksheets(); sysExcelWorksheet = sysExcelWorksheets.itemFromNum(1); excelRow = 2; SysExcelCell = SysExcelWorksheet.cells().item(excelRow,1); SysExcelCell.value("Col1"); SysExcelCell = SysExcelWorksheet.cells().item(excelRow,2); SysExcelCell.value("Col2"); SysExcelCell = SysExcelWorksheet.cells().item(excelRow,3); SysExcelCell.value("Col3"); // Save the Excel file sysExcelApplication.displayAlerts(false); sysExcelWorkbook.saveAs(fileName); sysExcelWorkBook.saved(true); sysExcelApplication.quit(); }
↧