5/17/2022

Axapta : Job LibreOffice Copy Sheet

 Axapta : Job LibreOffice Copy Sheet
ตัวอย่าง

  1. static void CopySheetOffice(Args _args)
  2. {
  3.  
  4. // ----------- OpenOffice -----------
  5.     COM         OpenOffice;
  6.     COM         oDeskTop;
  7.     COM         oDocument;
  8.     COM         oSheets;
  9.     COM         oSheet;
  10.     COM         oRange;
  11.     COM         BorderStruct;
  12.     COMVariant  arg;
  13.     COMVariant  byte;
  14.     Array       Arr = new Array(Types::Class);
  15.     Array       oArr = new Array(Types::Class);
  16.     str         url;
  17.     str         outFile;
  18.     COM         FileProperties;
  19.  
  20. // ----------- TABLE -----------
  21.     CustTable   custTable;
  22.  
  23. // ----------- VARIABLE -----------
  24.     int         rows = 1;
  25.     int         sheet = 2;
  26.  
  27. ///##### Function Print Trans #####//
  28.     void printTrans(){
  29.         rows++;
  30.         oRange = oSheet.getCellByPosition(0, rows);
  31.         oRange.SetString("123456");
  32.     }
  33.  
  34.     ;
  35.  
  36. // #####  Open template file ######
  37.     url = strfmt("%1%2", templatePath(), "/IV/ItemNotTransferByDate.ods");
  38.     OpenOffice  = new Com("com.sun.star.ServiceManager");
  39.     oDeskTop    = OpenOffice.CreateInstance("com.sun.star.frame.Desktop");
  40.     arg         = COMVariant::createFromArray(arr);
  41.     oDocument   = oDeskTop.LoadComponentFromURL(url, "_blank", 0, arg);
  42.     oSheets     = oDocument.getSheets();
  43.     oSheet      = oSheets.getByIndex(0);
  44.  
  45.     BorderStruct = OpenOffice.Bridge_GetStruct('com.sun.star.table.BorderLine');
  46.     BorderStruct.Color(24567057);
  47.     BorderStruct.LineDistance(0);
  48.     BorderStruct.InnerLineWidth(0);
  49.     BorderStruct.OuterLineWidth(1);
  50.  
  51. // #####  Save as temp file ######
  52.     DeleteFilesInFolder("C:/AxaptaSP4/Temp/IV/");
  53.     outFile = strfmt("file:///C:/AxaptaSP4/Temp/IV/ItemNotTransferByDate-%1.ods", timenow());
  54.     oDocument.storeAsURL(outFile, arg);
  55. // #######################################################################################
  56.  
  57.     WHILE
  58.     SELECT AccountNum FROM custTable
  59.     ORDER BY Name
  60.     WHERE custTable.CustGroup == "AUD"
  61.     {
  62.         oSheets.CopyByName("Template", custTable.AccountNum, sheet);
  63.         oSheet = oSheets.getByIndex(sheet);
  64.  
  65.         printTrans();
  66.  
  67.         rows = 1;
  68.         sheet++;
  69.     }//Close While.
  70.  
  71. }