2015-10-19 151 views
0

如何从进度导出到中间合并单元格的excel?当我尝试导出时,它没有自己。 例如预期输出:进度4gl到Excel导出与合并单元格

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

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

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

我的输出是什么:

unmerged cell value 1other value 1other value 1

unmerged cell value 2other value 2other value 2

unmerged cell value 3other value 3other 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. 

回答

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。但你可以改变它以满足你的需要) 。如果我忽略了您需要的任何其他信息,请告知我们。希望这可以帮助!