none
Used Range in Excel using OfficeOpenXml (EPPlus) RRS feed

  • Question

  • Hi,

    I know that Microsoft is not responsible for OpenXml but I am just throwing this question out there in case someone knows the answer to this. I am trying to translate a piece of code that saves an excel file from using Microsoft.Office.Interop to using OfficeOpenXml.

    How can I get the used range as an ExcelRange object?

    Excel.Range oRange = excelWorkSheet.UsedRange

    ExcelRange oRange = ???

    Thanks in advance





    • Moved by Terry Xu - MSFT Thursday, March 1, 2018 2:38 AM OpenXML related
    • Edited by Hackathor Thursday, March 1, 2018 4:03 PM confused library names
    • Moved by Terry Xu - MSFT Friday, March 2, 2018 6:33 AM
    Wednesday, February 28, 2018 7:59 PM

All replies

  • Hello Hackathor,

    What do you mean get the used range as an ExcelRange? OpenXML does no have a range property so you could not get a range object in OpenXML.

    If you want to get the address of the used range, you could try to get it from SheetDimension property.

    Here is the example.

    string Path = @"C:\Users\v-guaxu\Desktop\SourceFile.xlsx";
                using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(Path, true))
                {
                    WorkbookPart workbookPart = spreadSheet.WorkbookPart;
                    Workbook workbook = workbookPart.Workbook;
                    foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts) {                  
                        Console.WriteLine(worksheetPart.Worksheet.SheetDimension.Reference);
                    }
                }

    By the way, the thread is more related to OpenXML, so I would move it to OpenXML SDK forum. Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, March 1, 2018 2:36 AM
  • Thanks for the reply, but I seem to have gotten OpenXml and EPPlus's OfficeOpenXml confused. I meant to ask about how to get the used range as an ExcelRange object with EPPlus.

    Title updated.

    Thanks

    Thursday, March 1, 2018 4:03 PM
  • Hello Hackathor,

    This forum(Open XML Format SDK) is for development issues related to Open XML SDK and EPPlus is a third-part library so I would suggest you look for the library's support team for help. For current thread, I would move it Off-Topic forum. Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 2, 2018 6:33 AM