Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion OpenXmlFormats/Drawing/SpreadsheetDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,12 @@ public int SizeOfOneCellAnchorArray()

public static CT_Drawing Parse(XmlDocument xmldoc, XmlNamespaceManager namespaceManager)
{
XmlNodeList cellanchorNodes = xmldoc.SelectNodes("/xdr:wsDr/*", namespaceManager);
XmlNode root = xmldoc.SelectSingleNode("/xdr:wsDr", namespaceManager);
Comment thread
antony-liu marked this conversation as resolved.
if (root == null)
{
return new CT_Drawing();
}
XmlNodeList cellanchorNodes = root.SelectNodes("descendant::xdr:oneCellAnchor|descendant::xdr:twoCellAnchor|descendant::xdr:absCellAnchor", namespaceManager);
CT_Drawing ctDrawing = new CT_Drawing();
foreach (XmlNode node in cellanchorNodes)
{
Expand Down
19 changes: 19 additions & 0 deletions OpenXmlFormats/Spreadsheet/Sheet/CT_Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,25 @@ public void RemoveTableColumn(int columnIndex)
{
this.tableColumn.RemoveAt(columnIndex);
}

internal CT_TableColumn GetTableColumnArray(int v)
{
if (this.tableColumnField == null)
return null;
if (v < 0 || v >= this.tableColumn.Count)
throw new ArgumentOutOfRangeException();
return tableColumnField[v];
}

public CT_TableColumn AddNewTableColumn()
{
if(this.tableColumnField==null)
this.tableColumnField = new List<CT_TableColumn> ();
var c = new CT_TableColumn();
this.tableColumnField.Add(c);
return c;
}

[XmlElement]
public List<CT_TableColumn> tableColumn
{
Expand Down
21 changes: 18 additions & 3 deletions ooxml/XSSF/UserModel/XSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,22 @@ public ICellStyle CellStyle
}
}
}

/// <summary>
/// POI currently supports these formula types:
/// <list type="bullet">
/// <item><description> <see cref="ST_CellFormulaType.normal" /></description></item>
/// <item><description> <see cref="ST_CellFormulaType.shared" /></description></item>
/// <item><description> <see cref="ST_CellFormulaType.array" /></description></item>
/// </list>
/// POI does not support <see cref="ST_CellFormulaType.dataTable" /> formulas.
/// </summary>
/// <return>true if the cell is of a formula type POI can handle
/// </return>
private bool IsFormulaCell
{
get
{
if (_cell.f != null || ((XSSFSheet)Sheet).IsCellInArrayFormulaContext(this))
if ((_cell.f != null && _cell.f.t != ST_CellFormulaType.dataTable) || ((XSSFSheet)Sheet).IsCellInArrayFormulaContext(this))
{
return true;
}
Expand All @@ -773,7 +783,12 @@ private bool IsFormulaCell

}
/// <summary>
/// Return the cell type.
/// Return the cell type. Tables in an array formula return
/// <see cref="CellType.FORMULA" /> for all cells, even though the formula is only defined
/// in the OOXML file for the top left cell of the array.
/// <para>
/// NOTE: POI does not support data table formulas.
/// Cells in a data table appear to POI as plain cells typed from their cached value.</para>
/// </summary>
public CellType CellType
{
Expand Down
2 changes: 1 addition & 1 deletion ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,7 @@ public XSSFTable CreateTable()
false);
XSSFTable table = rp.DocumentPart as XSSFTable;
tbl.id = rp.Relationship.Id;

table.GetCTTable().id = (uint)tableNumber;
tables[tbl.id] = table;

return table;
Expand Down
107 changes: 67 additions & 40 deletions ooxml/XSSF/UserModel/XSSFTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,26 @@ public List<XSSFXmlColumnPr> GetXmlColumnPrs()
}
return xmlColumnPrs;
}

public void AddColumn()
{
// Ensure we have Table Columns
CT_TableColumns columns = ctTable.tableColumns;
if (columns == null)
{
columns = ctTable.AddNewTableColumns();
}

// Add another Column, and give it a sensible ID
CT_TableColumn column = columns.AddNewTableColumn();
int num = columns.tableColumn.Count;
columns.count = (uint)num;
column.id = (uint)num;

// Have the Headers updated if possible
UpdateHeaders();
}

/**
* @return the name of the Table, if set
*/
Expand Down Expand Up @@ -369,41 +389,38 @@ public XSSFTableColumn CreateColumn(String columnName, int columnIndex)

return GetColumns()[columnIndex];
}
/**
* Get the area reference for the cells which this table covers. The area
* includes header rows and totals rows.
*
* Does not track updates to underlying changes to CTTable To synchronize
* with changes to the underlying CTTable, call {@link #updateReferences()}.
*
* @return the area of the table
* @see "Open Office XML Part 4: chapter 3.5.1.2, attribute ref"
*/
public AreaReference GetCellReferences()

/// <summary>
/// <para>
/// Get or set the area reference for the cells which this table covers.
/// The area includes header rows and totals rows.</para>
/// <para>Does not track updates to underlying changes to CTTable To synchronize
/// with changes to the underlying CTTable, call <see cref="UpdateReferences"/></para>
/// </summary>
/// <remarks>
/// The area's width should be identical to the amount of columns in
/// the table or the table may be invalid. All header rows, totals rows and
/// at least one data row must fit inside the area. Updating the area with
/// this method does not create or remove any columns and does not change any
/// cell values.
/// @see "Open Office XML Part 4: chapter 3.5.1.2, attribute ref"
/// </remarks>
public AreaReference CellReferences
{
return new AreaReference(
get
{
return new AreaReference(
StartCellReference,
EndCellReference,
SpreadsheetVersion.EXCEL2007
);
}
/**
* Set the area reference for the cells which this table covers. The area
* includes includes header rows and totals rows. Automatically synchronizes
* any changes by calling {@link #updateHeaders()}.
*
* Note: The area's width should be identical to the amount of columns in
* the table or the table may be invalid. All header rows, totals rows and
* at least one data row must fit inside the area. Updating the area with
* this method does not create or remove any columns and does not change any
* cell values.
*
* @see "Open Office XML Part 4: chapter 3.5.1.2, attribute ref"
*/
public void SetCellReferences(AreaReference refs)
{
SetCellRef(refs);
);
}
set
{
SetCellRef(value);
}
}

protected void SetCellRef(AreaReference refs)
{

Expand Down Expand Up @@ -476,6 +493,7 @@ public long NumberOfMappedColumns
return ctTable.tableColumns.count;
}
}

public int ColumnCount
{
get
Expand Down Expand Up @@ -610,15 +628,23 @@ public int RowCount
}


/**
* Synchronize table headers with cell values in the parent sheet.
* Headers <em>must</em> be in sync, otherwise Excel will display a
* "Found unreadable content" message on startup.
*
* If calling both {@link #updateReferences()} and
* {@link #updateHeaders()}, {@link #updateReferences()}
* should be called first.
*/
/// <summary>
/// <para>
/// Synchronize table headers with cell values in the parent sheet.
/// Headers <em>must</em> be in sync, otherwise Excel will display a
/// "Found unreadable content" message on startup.
/// </para>
/// <para>
/// If calling both <see cref="UpdateReferences()" /> and
/// <see cref="UpdateHeaders()" />, <see cref="UpdateReferences()" />
/// should be called first.
/// </para>
/// <para>
/// Note that a Table <em>must</em> have a header. To reproduce
/// the equivalent of inserting a table in Excel without Headers,
/// manually add cells with values of "Column1", "Column2" etc first.
/// </para>
/// </summary>
public void UpdateHeaders()
{
XSSFSheet sheet = (XSSFSheet)GetParent();
Expand All @@ -630,6 +656,7 @@ public void UpdateHeaders()
int firstHeaderColumn = ref1.Col;

XSSFRow row = sheet.GetRow(headerRow) as XSSFRow;
DataFormatter formatter = new DataFormatter();

if (row != null && row.GetCTRow() != null)
{
Expand All @@ -642,7 +669,7 @@ public void UpdateHeaders()
{
if (row.GetCell(cellnum) is XSSFCell cell)
{
col.name = cell.StringCellValue;
col.name = formatter.FormatCellValue(cell);
}
cellnum++;
}
Expand Down
37 changes: 0 additions & 37 deletions testcases/ooxml/XSSF/UserModel/TestUnfixedBugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,43 +355,6 @@ private void checkRow57423(ISheet testSheet, int rowNum, String contents)
ClassicAssert.AreEqual(contents, cell.ToString(), "Did not have expected contents at rownum " + rowNum);
//ClassicAssert.AreEqual(contents + ".0", cell.ToString(), "Did not have expected contents at rownum " + rowNum);
}

[Test]
public void test58325_one()
{
check58325(XSSFTestDataSamples.OpenSampleWorkbook("58325_lt.xlsx"), 1);
}
[Test]
[Ignore("TODO FIX CI TESTS")]
public void test58325_three()
{
check58325(XSSFTestDataSamples.OpenSampleWorkbook("58325_db.xlsx"), 3);
}
private void check58325(XSSFWorkbook wb, int expectedShapes)
{
XSSFSheet sheet = wb.GetSheet("MetasNM001") as XSSFSheet;
ClassicAssert.IsNotNull(sheet);
StringBuilder str = new StringBuilder();
str.Append("sheet " + sheet.SheetName + " - ");
XSSFDrawing drawing = sheet.GetDrawingPatriarch();
//drawing = ((XSSFSheet)sheet).createDrawingPatriarch();
List<XSSFShape> shapes = drawing.GetShapes();
str.Append("drawing.Shapes.size() = " + shapes.Count);
IEnumerator<XSSFShape> it = shapes.GetEnumerator();
while (it.MoveNext())
{
XSSFShape shape = it.Current;
str.Append(", " + shape.ToString());
str.Append(", Col1:" + ((XSSFClientAnchor)shape.GetAnchor()).Col1);
str.Append(", Col2:" + ((XSSFClientAnchor)shape.GetAnchor()).Col2);
str.Append(", Row1:" + ((XSSFClientAnchor)shape.GetAnchor()).Row1);
str.Append(", Row2:" + ((XSSFClientAnchor)shape.GetAnchor()).Row2);
}

ClassicAssert.AreEqual(expectedShapes, shapes.Count,
"Having shapes: " + str);
}

}
}

Loading
Loading