Please see attached file to understand this. The issue is I am deleting cells but i am losing value in a cell which has a vertical merge even though i do not delete this cell or change it’s text.
With reference to the file i have some code that deletes rows if their value is 0.00. In the attached file I delete rows 1, 2 and 4 as these values are 0.00. I can’t use row.delete as I want to keep the the merged cell on the left so i delete the cells like below.
In theory I should have one row with “You have bought…”, “Carpets” and 11.00 in it. The delete code works but for some reason the first cells text has disappeared. Any ideas why?
I was unable to reproduce this issue using the latest version of Aspose.Words for .NET i.e. 15.1.0. Please test with the latest version and let us know if you see any issue.
Looking at code again and tried latest aspose and it is does a similar thing.
I have made a bit of headway though. If I do not delete any cells in the first row this works fine which isn’t helpful as do no know which rows will be 0 or not but at least It could help in some way. The method I use is below. I would send full example but there is a lot going on! If I pass in the first row (index 0) the text in the far left column disappears even though I do not delete or edit it, if i leave the first row pass in 2nd,3rd or (x) row then the text in far left cell stays.
public void removeTableRow(Aspose.Words.Tables.Row row, Document doc)
{
//Since there is a vertical Merge I cannot delete far left column
if (row.Cells[0].CellFormat.VerticalMerge != Aspose.Words.Tables.CellMerge.None)
{
int cellCount = row.Cells.Count;
for (int i = cellCount - 1; i > 0; i–)
{
Aspose.Words.Tables.Cell currentCell = row.Cells[i];
// currentCell.RemoveAllChildren();
currentCell.Remove();
}
}
else
{
// //Since no merging on far left column I can just remove row
row.Remove();
}
}
Sorry, I was still unable to reproduce the issue using the latest version. I was getting the attached DOC when I used the code from your first post. Now I passed rows 1, 2 and 4 with index 0, 1 and 3 respectively to the method you shared and I get attached DOCX file in the output.
Please share a running application to reproduce the issue if you are getting a different output.
I have created a small demo app (c# console app) and still can see what issue is now. Looks like the latest aspose nearly does what I want but the older version I currently use does something I want so Ideally I want a combination of the two!. I have attached two output files one is for v10.4.0.0 and one uses aspose 14.10.0.0. For 14.10.0.0 it deletes cells and the text in the left cell stays which is what i want but annoyingly there are spaces present. V10.4.0.0.0 the rows do disappear which Is what I expect but the the text “Since then you have…” has gone. Is there any way of making the row height 0 for 14.10.0.0 or something similar?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Words.Drawing;
using Aspose.Words.Fields;
using Aspose.Words;
namespace testApp
{
class Program
{
static void Main(string[] args)
{
//string licenseFile = "Aspose.Words.lic";
//Aspose.Words.License license = new Aspose.Words.License();
// license.SetLicense(licenseFile);
Aspose.Words.Document doc = new Document(@"C:\Users\Matthew Bryant\Desktop\Valuation files\example.doc");
Aspose.Words.Tables.Table tempT = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
//3-6
Aspose.Words.Tables.Row ROW6 = tempT.Rows[6];
int COUNT = ROW6.Cells.Count;
tempT.Rows[6].Cells[2].Remove();
tempT.Rows[6].Cells[1].Remove();
tempT.Rows[5].Cells[2].Remove();
tempT.Rows[5].Cells[1].Remove();
tempT.Rows[3].Cells[2].Remove();
tempT.Rows[3].Cells[1].Remove();
doc.Save(@"C:\Users\Matthew Bryant\Desktop\Valuation files\exampleCopy.pdf", Aspose.Words.SaveFormat.Pdf);
}
}
}
What I have understood from your post is that latest version of Aspose.Words is removing the cells but not shifting the cells up and leaving the space of removed cells intact. Are you referring to the same issue?
Thanks for the confirmation. This feature is not available at the moment but a new feature request to support this option has been logged into our issue tracking system as WORDSNET-11664. You will be able to remove empty space while deleting the cells when this option is available.
We will keep you updated on this issue in this thread. Sorry for the inconvenience.