Cell Padding Displaces Border


#1

Looks like cell padding causes borders to shift. You can see little areas of white where the borders should have been. I’ve attached the Word document.

Thanks.


#2

Hi,

Thank you for considering Aspose.

So has this document been produced by Aspose.Word? Are you experiencing any problems with it?


#3

Yes, that was produced with Aspose.Word. Hopefully you can reproduce this bug because I’m having trouble creating a version of this project that I can send to you.

For some reason I’m getting a MissingMethodException on System.DateTime.FromFileTimeUtc(Int64) when I port my code to a new project. The exception is thrown when I do:

Dim wrdDocument As Aspose.Word.Document = New Aspose.Word.Document( )



#4

I created a new 2003 project that uses .NET 1.1 and that solved the problem. I’ve attached my project. The input is ready to go, so just open the project, run it and the resulting Word document will be in the “output” folder.

Thanks for your help.


#5

You’ll see that the borders are shifting by the cell padding amount, and the table contents should be aligned left but are centered instead.


#6

Have you been able to resolve this issue?

Thanks.


#7

Sorry for the delay and expect the reply very soon.


#8

Thank you for the project. You’ve done a great job on making your own implementation of HTML and CSS importing. We are looking at the issue at the moment and we will notify you as soon as have figured out the cause.


#9

We are looking to release the Word exporter on the 16th. If you can resolve this problem by then, that would be great.

Thanks, Natan.


#10

I looked at the issue and here is what I can say:

If you build a table in MS Word and modify left cell padding - it will affect the horizontal position of the table or row in some cases.

The problem is I cannot quite follow the logic MS Word employs for this so there is no way I can make Aspose.Word do exactly the same. In fact MS Word does very different things for left, center and right aligned tables. To keep the scope limited, lets talk about left aligned tables only.

In MS Word if you modify left padding of the first cell in the first row - it will move the whole table horizontally. But if you modify left padding of the first cell in any other row - it will not move the table.

Aspose.Word is only different from the above in that it treats all rows of a table independently (every row for Aspose.Word is like a first row), therefore if you modify left padding of the first cell, it will move the row horizontally.

I don't want to fix or change this behaviour right now, but you can easily workaround to achieve what you want.

You can use RowFormat.LeftIndent and/or ParagraphFormat.LeftIndent in conjuction or instead of using LeftPadding.

For example, to create two rows that start on the same horizontal position, but first cells have different padding you can do this:

builder.InsertCell();
builder.CellFormat.LeftPadding = 0;
builder.Write("Left padding 0pt");
builder.EndRow();

builder.InsertCell();
builder.CellFormat.LeftPadding = 36;
//Since the first cell padding "moved" the row 36pt to the left, add
//same amount of indent at the left of the row to compensate.
builder.RowFormat.LeftIndent = 36;
builder.Write("Left padding 36pt");
builder.EndRow();
builder.EndTable();


Probably a cleaner approach is to use Paragraph.LeftIndent (it is likely to be more future proof than using cell padding):

builder.CellFromat.LeftPadding = 0;

builder.InsertCell();
builder.Write("Left indent 0pt");
builder.EndRow();

builder.InsertCell();
builder.ParagraphFormat.LeftIndent = 36;
builder.Write("Left indent 36pt");
builder.EndRow();
builder.EndTable();



#11

I will try this workaround. As I understand, this affects all tables (regardless of horizontal alignment on the page) but only LeftPadding? So if I simply replace the line:

builder.CellFormat.LeftPadding

with

builder.ParagraphFormat.LeftIndent

Will this prevent the borders from shifting? Do I need to also ensure that LeftPadding equals 0?

Thanks.


#12

You don’t have to set CellFormat.LeftPadding to zero. The problem only manifests itself when you have different LeftPadding for first cells of different rows - the rows start from different horizontal positions as a result.


#13

I’ve modified my code and your workaround works perfectly. Thanks!