none
How to use SingleCellTablePart?? RRS feed

  • Question

  • I am trying to retrieve the value of a cell from a worksheet. I guess SingleCellTablePart is the right object to use but not sure how to use it as there is not documentation on this.
    Thursday, June 7, 2007 6:29 AM

Answers

  • Ni Hao, Patrick Smile

     

    If you unzip the xlsx file, you'll see a workbook.xml file. This file has a node to describe the sheet information, for example:

    <sheets>

      <sheet name="Sheet1" sheetId="1" r:id="rId1" />
      <sheet name="Sheet2" sheetId="2" r:id="rId2" />
      <sheet name="Sheet3" sheetId="3" r:id="rId3" />
      </sheets>

     

    Usually when you want to retrieve something, you know the sheet name as it can be shown from excel, you should get the value of r:id according to the sheet name then you can call WorkbookPart.GetPartById() to load the sheet and get the cell value you want.

     

    --Haiyang

    U
    U
     
    U
    • Marked as answer by Patrick Yong Wednesday, December 23, 2009 3:30 PM
    Friday, June 8, 2007 2:24 AM

All replies

  • Hi, Patrick,

     

    I am afraid that the SingleCellTable is not the right object to use. According to the OpenXML spec:

     

      A single cell table is generated from an XML mapping. These really just look like regular cells to the spreadsheet user, but shall be implemented as   Tables "under the covers." 

      These tables don't have the full set of properties that multi cell tables do. They only have the various XML properties, and core table properties (such as id and name) that are needed to create a table and XML mapping.

     

    Actually you should load the WorkbookPart of the document, then find the sheet id by the sheet name you want to operate. After get the sheet id, you can load the sheet document by calling WorkbookPart.GetPartById(). Then you can navigate to the right place using xpath to find the right cell and get value.

     

    Hope this helps.

    Thursday, June 7, 2007 8:06 AM
  • Haiyang Ni Hao!!

     

    Thanks for the reply. When you mention sheet id, is it the same as sheet name?

     

    -Patrick

    Friday, June 8, 2007 1:25 AM
  • Ni Hao, Patrick Smile

     

    If you unzip the xlsx file, you'll see a workbook.xml file. This file has a node to describe the sheet information, for example:

    <sheets>

      <sheet name="Sheet1" sheetId="1" r:id="rId1" />
      <sheet name="Sheet2" sheetId="2" r:id="rId2" />
      <sheet name="Sheet3" sheetId="3" r:id="rId3" />
      </sheets>

     

    Usually when you want to retrieve something, you know the sheet name as it can be shown from excel, you should get the value of r:id according to the sheet name then you can call WorkbookPart.GetPartById() to load the sheet and get the cell value you want.

     

    --Haiyang

    U
    U
     
    U
    • Marked as answer by Patrick Yong Wednesday, December 23, 2009 3:30 PM
    Friday, June 8, 2007 2:24 AM