【问题标题】:excel close a specific worksheetexcel关闭特定工作表
【发布时间】:2016-08-16 23:57:46
【问题描述】:

我正在编写一个从 excel 生成报告的 foxpro 程序。在最后的过程中,程序生成了两(2)个excel。我创建了一个新工作簿并将两个输出 excel 表复制到新工作簿中。如何关闭这两个excel文件?

我的代码

**creating new workbook
XL = tmp.application
XL.workbooks.ADD()
XL.visible = .T.
XLsheet = XL.ActiveSheet

**opening the aging excel output
sheetdir=SYS(5)+SYS(2003)+"\temp\EXCEL1.xls"
XL.workbooks.OPEN(sheetdir)
XL.worksheets.COPY(XLsheet)
XL.ActiveSheet.UsedRange.EntireColumn.Autofit
XL.ActiveSheet.name="P1"
xl.cells(1,1).value="xx"

XLsheet = XL.ActiveSheet
**opening the unvalidated excel output
sheetdir=SYS(5)+SYS(2003)+"\temp\EXCEL2.xls"
XL.workbooks.OPEN(sheetdir)
XL.worksheets.COPY(XLsheet)
XL.ActiveSheet.UsedRange.EntireColumn.Autofit
XL.ActiveSheet.name="P2"

【问题讨论】:

    标签: visual-foxpro excel-automation


    【解决方案1】:

    这是我的工作:

    #define xlNormal 39  && defines the version of Excel
    oxl = createobject("Excel.Application")
    oxl.Workbooks.add()
    oBook = oxl.ActiveWorkbook()
    oxl.visible = .f.
    osheet = oxl.activesheet
    
     && update the worksheet
    
     oxl.DisplayAlerts = .f. && do not invoke any dialog 
    
     oBook.saveas(mfilex,xlNormal )
     && you can use oBook.Close() if you just want to close the book without saving
    
     oxl.quit()
     release oxl
    

    【讨论】:

    • 但我目前需要打开合并的 excel。我在想我是否可以使用将 Excel 表移动到我的工作工作簿。
    • 您不需要复制和粘贴。您可以使用 Copy() 方法从另一个工作簿和/或工作表中复制工作表。
    • 我使用 move() 方法,其他两个工作簿将关闭。
    【解决方案2】:

    您可以使用 Workbook 的 Close() 方法。

    PS:请检查您之前的问题并关闭它们。

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多