【问题标题】:How to get excel range topleft and bottomright cell in en Excel worksheet.如何在 en Excel 工作表中获取 Excel 范围左上角和右下角单元格。
【发布时间】:2016-03-26 07:41:44
【问题描述】:

我想找到 Excel 工作表范围内的左上角单元格和右下角单元格,这是工作表中所有占用单元格的边界框,来自 win 7 上的 ironpython 2.7.5。

我的代码:

 from Microsoft.Office.Interop import Excel
 from System import Type

 excel = Excel.ApplicationClass()
 workbook = excel.Workbooks.Open(excelFilename, False, True)
 allWorksheets = workbook.WorkSheets
 for aWorkSheet in allWorksheets:
      last = aWs.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
      range = excel.get_Range("A1", last);
      print "a worksheet range is " + str(range)

我需要在“范围”中找到左上角单元格和右下角单元格

处的链接

Programmatically getting the last filled excel row using C#

How to get the range of occupied cells in excel sheet

帮不了我。

有什么建议吗?谢谢

【问题讨论】:

    标签: excel python-2.7 ironpython worksheet


    【解决方案1】:

    您可以像这样使用.Value 获取范围:

     ws.Range("A3:B4").Value = "A3:B4"
    

    ranges_and_offsets.py 示例的第 11 行所示。

    【讨论】:

    • 谢谢,但我需要知道范围的左上角单元格地址和右下角单元格地址。
    • 在我的示例中列出的范围内,A3 是左上角,B4 是右下角
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2021-10-30
    • 1970-01-01
    相关资源
    最近更新 更多