Border in Tables

Sep 22, 2009 at 9:12 AM

Hello,

I just started using your library.
I think is very useful.

Just a question: is it possible to manage borders of a table ?

I have added a table programmatically but I could not manage table-borders; 
For example I would hide them or change thikness or color.

 

Thanks in advance

Luca
Italy
www.artmedia.it

 

Coordinator
Sep 22, 2009 at 9:31 AM
cyberfester,

I have been working on an updated version of DocX.dll. This version of DocX has basic support for setting the border of a Cell.Below is an example of how to use this new feature, please see the below example code.

// Load the test document.
using (DocX document = DocX.Load("Test.docx"))
{
    // Grab the first Table in this document.
    Table t = document.Tables[0];

    // Grab the middle cell from this Table.
    Cell middle_cell = t.Rows[1].Cells[1];

    /*
     * Set the top, bottom, left and right borders of this cell,
     * to different types, sizes and colors.
     */
    middle_cell.borders.Top = new Border(BorderType.singleLine, 4, Color.Red);
    middle_cell.borders.Bottom = new Border(BorderType.doubleLine, 5, Color.Orange);
    middle_cell.borders.Left = new Border(BorderType.tripleLine, 6, Color.Blue);
    middle_cell.borders.Right = new Border(BorderType.wave, 7, Color.Pink);

    // Save this document as Test2.docx
    document.SaveAs("Test2.docx");
}

Please note: I intend to add helper functions, which will reduce the amount of code required to do common tasks with borders, like the below function.

// Cell.SetBorders(bool leftBorder, bool rightBorder, bool topBorder, bool bottomBorder, Border newBorder)
middle_cell.SetBorders(true, true, true, true, new Border(BorderType.singleLine, 4, Color.Red));

If you send me your email address, I will forward you the updated dll and an example document.
kind regards,
Cathal
Apr 2, 2010 at 10:13 AM

Dear Cathal,

Thank you for sharing your great library.

Are you planning any future updates of this library on this website also? 
I am looking forward to an update including the 'cell border support'.

Keep up the good work.

Kind regards,

Luuk
The Netherlands

Coordinator
Apr 2, 2010 at 10:27 AM
Hi lckuiper,

I will be releasing a new version of DocX in early June. This version as with all previous versions will be uploaded to docx.codeplex.com. I will add lots of features to this version including border support.

kind regards,
Cathal
Oct 29, 2010 at 7:57 PM

Hi Cathal,

I've just started using your library as well.

I'm looking for a method of styling borders of cells after inserting rows into a table and haven't been able to find a reference to the borders object in cell mentioned above.

Did this make it into the current release?

Thanks so much!

Evan

Nov 5, 2010 at 3:39 PM

Hi Cathal,

It would be really nice if it would make it into the next release! Looking forward to it.

Thanks in advance,

Luuk

 

Nov 15, 2010 at 9:54 PM

Hi Cathal,

Just uploaded two 'patches' (just code files) with patch ids #7387 and #7389. The code files in #7389 also contain the update of #7387.

I added properties / functions for:

- #7387 + #7389: setting table cell margins (left, right, top, bottom, start and end)

- #7389: setting table cell borders (for now left, right, top and bottom)

Maybe you can use this code for the next release.

Kind regards,

Luuk Kuiper
Acsense Software, Netherlands

Nov 15, 2010 at 9:59 PM

One note for the new >= 57500 source code releases:

- This change: Removed a few function overloads by utilising .NET 4.0 optional parameters

makes the project 'unusable' for Visual Studio 2008 (had to remove the optional parameters to make it build the project).

Visual Studio 2008 does not seem to support developing against .NET 4.0 (CLR is different from .NET 3.5).

 

Kind regards,
Luuk

 

Coordinator
Nov 16, 2010 at 5:44 PM
lckuiper,

I am sorry. I did not realise Visual Studio 2008 was incapable of building against .NET 4.0. This is such a pity. I would like to use optional parameters and other cool 4.0 features but I do not wish to lose users who for one reasons or another cannot use .NET 4.0.

I will remove optional parameters for now. Look out for a change-set that reverts the changes I made in 57500.

Cathal