使用合并单元格进行4gl到Excel导出

时间:2015-10-19 00:29:14

标签: excel merge cell progress-4gl openedge

如何从进度导出到中间合并单元格的Excel?当我尝试导出时,它会自行解散。 示例预期输出:

merged cell with value 1 (3 cells) other value 1 other value 1

merged cell with value 2 (3 cells) other value 2 other value 2

merged cell with value 3 (3 cells) other value 3 other value 3

我的输出是什么:

unmerged cell value 1 other value 1 other value 1

unmerged cell value 2 other value 2 other value 2

unmerged cell value 3 other value 3 other value 3

导出到Excel代码:

DEFINE VARIABLE h-excel AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE h-sheet AS COM-HANDLE.
DEFINE VAR w-invname AS CHAR INITIAL "insert excel fill here".
CREATE "Excel.Application" h-excel.

h-sheet = h-excel:Workbooks:OPEN (w-invname,,FALSE,,,,,,,,,,FALSE) NO-ERROR.
h-excel:visible = true.

h-excel:Cells:Select.
/*h-excel:Selection:ClearContents.*/

h-excel:Run("loading").  /* Run the Macro, up to 31 optional   */
                           /* parameters can be passed           */
/*h-excel:Quit().*/            /* Tell Excel to quit                 */

/*h-excel:Range("A" + STRING(5)):VALUE = "Date Covered " + STRING(fifr) + " - " + STRING(fito).*/
h-excel:Range("A" + STRING(6)):VALUE = "As of " + cbMon + STRING(fiyear).

h-excel:Range("A12"):Select.
/*h-excel:Workbooks:SaveAs("c:\hckiv9\crd\forms\KMCDAT1.xls",43,,,,,).*/

RELEASE OBJECT h-sheet.
RELEASE OBJECT h-excel.

END PROCEDURE.

1 个答案:

答案 0 :(得分:0)

好吧,我不知道我是否理解你的意图,但是你提供的样本中没有代码可以合并。以下是我快速整理的内容:

DEFINE VARIABLE chExcel       AS COM-HANDLE      NO-UNDO.
DEFINE VARIABLE chSpreadsheet AS COM-HANDLE      NO-UNDO.

/* Excel Creation, not relevant to the question, but preparing the answer */
create "Excel.Application" chExcel.
chExcel:WorkBooks:add. 
chExcel:sheets:item(1).
chSpreadsheet = chExcel:Worksheets("Sheet1").

   /* This line merges the two cells */
   chSpreadsheet:range('b2:c2'):merge().

   /* This line selects the merged cells */
   chSpreadsheet:range('b2:b2'):select().

   /* The next puts a value to B2 (Which is now merged with C2) */
   chSpreadsheet:cells(2,2) = 'test'.

   /* Make Excel visible to the user */
   chExcel:visible = true.

   /* Release handles, you may dispose of Excel here and add a quit if you 
      don't want to leave the screen hanging for the user */
   chSpreadsheet = ?.
   chExcel = ?.

所以实际回复你问题的那一行是我在Excel启动后立即进行的合并。现在,范围,不像细胞(你可能提供两个以逗号分隔的整数),据我所知,将需要一个范围字符串(在我们的例子中,B2:c2。但你可以改变它以满足你的需要) 。如果我忽略了你需要的任何东西,请告诉我。希望这有帮助!