We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Table Formatting issue when using builder.InsertCell()

Hi Team,

I am getting some formatting issues. When I generate the table using builder.InsertCell() logic.I am able to render the desired table in MS WORD. Please see the attatchment. But I am not able to render formatting properly using builder.InsertCell() . If you see the attachment all the cells are stick with each other. If I want to increase the eg:- "Media Type" cell width manually or dynamically it also increase the "Language" and "Restriction" cells.

Now if u see the template.doc which I sent you in attatchment, there is another table with heading "Media Rights" this is what I required. Here each cells in table are free from wach other. In this table if I increase the "Media Type" cell width by manually or dynamically "Sublicense" and "Restriction" cells width does not change.

Below are my questions if I am generating table using builder.InsertCell() :

1. How to make table cells free of each rows?

2. How to set the left indent? please see the second table "Row No" cell starting position

3. How to fixed the width of a cell ? currently it start increasing the width of cell if the content is big in a cell. I am using below code:

Aspose.Words.Tables.CellFormat cellFormat = builder.CellFormat;

cellFormat.Width = 40;

builder.write("Hello");

4. Last but not least "HOW CAN I CREATE SAME TABLE AS IT SHOWN IN TEMPLATE WITH HEADING "MEDIA RIGHTS" FROM BUILDER.INSERTCELL()"

I will be very thankfull to you if you can provide me some sample which fullfill my above questions?

Thanks

Deepak

Hi Deepak,


Thanks for your inquiry. Please see the following code which helps in meeting the requirements you mentioned in 1st, 3rd and 4th points:

Document doc = new
Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Table tab = builder.StartTable();

builder.InsertCell();

builder.Writeln("Row 1 Cell 1");

builder.CellFormat.Width = 250;

builder.InsertCell();

builder.Writeln("Row 1 Cell 2");

builder.CellFormat.Width = 50;

builder.EndRow();

builder.InsertCell();

builder.Writeln("Row 2 Cell 1");

builder.CellFormat.Width = 150;

builder.InsertCell();

builder.Writeln("Row 2 Cell 2");

builder.CellFormat.Width = 200;

builder.EndRow();

builder.EndTable();

tab.AutoFit(AutoFitBehavior.FixedColumnWidths);

doc.Save(@“C:\Temp\out.docx”);


Regarding 2nd point, it seems Row margin are not working in Aspose.Words as expected. I have logged this problem in our issue tracking system as WORDSNET-9851. We will further look into the details of this problem and keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Awais,

Any update on this WORDSNET-9851? Or if there is any workaround of this by which I can slide some rows from left in table so that it looks like nested rows .

Please refer the attatchement I attatched earlier. If any workground available can you please share the code to me?

This is urgent requirenment.

Thanks

Deepak

Hi Deepak,


Thanks for your inquiry. Unfortunately, this issue is not resolved yet. Currently, this issue is pending for analysis and is in the queue. We will inform you as soon as this issue is resolved. We apologize for any inconvenience.

As a workaround, you can insert an empty invisible cells to the left of the rows as follows:

Document doc = new
Document(MyDir + @"\template.doc");

Table tab = doc.FirstSection.Body.Tables[doc.FirstSection.Body.Tables.Count - 1];

Cell cell = new Cell(doc);

cell.CellFormat.Borders.LineStyle = LineStyle.None;

cell.CellFormat.Width = 72 * 2;

tab.Rows[1].Cells.Insert(0, cell);

doc.Save(MyDir + @"\out.doc");


I hope, this helps.

Best regards,