合并单元格
//合并比较简单
//横向
cell.CellFormat.HorizontalMerge = CellMerge.First; //开始合并单元格
cell.CellFormat.HorizontalMerge = CellMerge.Previous; //被合并
cell.CellFormat.HorizontalMerge = CellMerge.None; //无
//纵向
cell.CellFormat.VerticalMerge = CellMerge.First;
cell.CellFormat.VerticalMerge = CellMerge.Previous;
cell.CellFormat.VerticalMerge = CellMerge.None;
拆分单元格
对于已经被合并的单元格,再次读取时已经读不到原来的总列数了,这时需要用table.ConvertToHorizontallyMergedCells();转换为以列宽显示的合并单元格,这时就能读取到所有的单元格信息了,把被合并的单元格都取消掉,或者仅处理需要处理的之后需要doc.UpdatePageLayout();刷新表格。不然再次读取修改表格合并时会把表格打乱。
//表格预先处理
foreach (Section section in doc.Sections)
{
foreach (Table table in section.Body.Tables)
{
if (true)
{
//合并属性补全(关键操作)
table.ConvertToHorizontallyMergedCells();
//清空合并属性
foreach (Row itemrow in table.Rows)
{
foreach (Cell cell in itemrow.Cells)
{
cell.CellFormat.HorizontalMerge = CellMerge.None;
cell.CellFormat.VerticalMerge = CellMerge.None;
}
}
}
}
}
doc.UpdatePageLayout();
//表格预先处理结束
删行
public static void DealDelRowList_Aspose(Aspose.Words.Tables.Table TableOne, int count)
{
for (int i = 0; i < count; i++)
{
spireTableOne.Rows.Remove(TableOne.Rows[spireTableOne.Rows.Count - 1]);
}
}
删列
<