Tables in Word automation

A

Andrey Dzizenko

Hi!

Could anyone please explain me how to work with Word table borders
correctly?

I wrote a method like that:

private void ProcessBorder(Range range, WdBorderType borderType)
{
SmartLog.Log();

Border border = range.Cells.Borders[borderType];
if (border.Visible)
{
// Line is my own class
Line line = new Line();
line.Color = (int)border.Color;
line.Start.Top.FromPoints(
(float)_application.Selection.get_Information(
WdInformation.wdVerticalPositionRelativeToPage)
+ ((borderType == WdBorderType.wdBorderBottom) ? range.Cells.Height : 0)
);
line.Start.Left.FromPoints(
(float)_application.Selection.get_Information(
WdInformation.wdHorizontalPositionRelativeToPage)
+ ((borderType == WdBorderType.wdBorderRight) ? range.Cells.Width: 0)
);

// Code for getting end point of line
// ...
}
}


But that method sets incorrect position of borders. Maybe I'm completely
wrong.

Thank you in advance.
 
C

Cindy M.

Hi Andrey,
Could anyone please explain me how to work with Word table borders
correctly?
Table borders aren't created from drawing lines (shapes). There's no way to
link them to the table.

Start with something like this, to make the borders visible (this is VBA
code) and blue:

range.Cells.Borders(borderType).Enable = true
range.Cells.Borders.OutsideColor = wdColorBlue
I wrote a method like that:

private void ProcessBorder(Range range, WdBorderType borderType)
{
SmartLog.Log();

Border border = range.Cells.Borders[borderType];
if (border.Visible)
{
// Line is my own class
Line line = new Line();
line.Color = (int)border.Color;
line.Start.Top.FromPoints(
(float) application.Selection.get Information(
WdInformation.wdVerticalPositionRelativeToPage)
+ ((borderType == WdBorderType.wdBorderBottom) ? range.Cells.Height : 0)
);
line.Start.Left.FromPoints(
(float) application.Selection.get Information(
WdInformation.wdHorizontalPositionRelativeToPage)
+ ((borderType == WdBorderType.wdBorderRight) ? range.Cells.Width : 0)
);

// Code for getting end point of line
// ...
}
}


But that method sets incorrect position of borders. Maybe I'm completely
wrong.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
A

Andrey Dzizenko

No, it seems to me that you didn't understand.

I have an opened document with existing tables and borders.
Now I want to get borders coordinates and transform them to lines.



Hi Andrey,
Could anyone please explain me how to work with Word table borders
correctly?
Table borders aren't created from drawing lines (shapes). There's no way
to
link them to the table.

Start with something like this, to make the borders visible (this is VBA
code) and blue:

range.Cells.Borders(borderType).Enable = true
range.Cells.Borders.OutsideColor = wdColorBlue
I wrote a method like that:

private void ProcessBorder(Range range, WdBorderType borderType)
{
SmartLog.Log();

Border border = range.Cells.Borders[borderType];
if (border.Visible)
{
// Line is my own class
Line line = new Line();
line.Color = (int)border.Color;
line.Start.Top.FromPoints(
(float) application.Selection.get Information(
WdInformation.wdVerticalPositionRelativeToPage)
+ ((borderType == WdBorderType.wdBorderBottom) ? range.Cells.Height
: 0)
);
line.Start.Left.FromPoints(
(float) application.Selection.get Information(
WdInformation.wdHorizontalPositionRelativeToPage)
+ ((borderType == WdBorderType.wdBorderRight) ? range.Cells.Width :
0)
);

// Code for getting end point of line
// ...
}
}


But that method sets incorrect position of borders. Maybe I'm completely
wrong.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)


This reply is posted in the Newsgroup; please post any follow questionor
reply in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi Andrey,
No, it seems to me that you didn't understand.

I have an opened document with existing tables and borders.
Now I want to get borders coordinates and transform them to lines.
You're correct - I didn't understand.

I'm not sure this is going to be possible. Word is not really
co-ordinate oriented - it's primarily concerned about text flow.
There is simply no way to accurately get the co-ordinates where a
table border (or anything else, for that matter) appears on a page.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
A

Andrey Dzizenko

Bad news...

There're too many problems with Word =)
I'm gonna save Word document as rtf and then parse it. I think it is the
one solution.

Thanks a lot...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top