Using PowerShell to modify MS Word cell borders - powershell

I routinely create reports using MS Word. Part of this report contains a table, which I have been copying manually from Excel into the word document. I am trying to use PowerShell in order to do this automatically, but I am having trouble finding the correct formatting commands. Specifically, I am currently trying to format the table so that every border between rows is dotted instead of solid, but the borders between columns are invisible. So something like this:
Heading1 Heading2 Heading3
.................................................
H1Item1 H2Item1 H3Item1
.................................................
H1Item2 H2Item2 H3Item2
.................................................
I did find that this gets me going in the right direction, but doesn't quite provide the granularity of border control that I'm looking for:
$Table.Range.Style = "Table Grid"
$Table.Borders.InsideLineStyle = 2
$Table.Borders.OutsideLineStyle = 0
If there is any good documentation on formatting Word paramters through PowerShell, I would really appreciate the pointer. I've managed to find articles relating to how to do specific things, but no good documentation.

Aha! I found it. I was trying for a way to do it in one line, but I found that if I just edit each row as I'm adding the data to it, then I can get the whole table that way. This is the line I added to my Foreach loop:
$Table.Rows($x).Borders.InsideLineStyle = 0
I would still love a link to some good documentation if anyone knows of any!

Related

Autoformat word table in perl

I have created a word document in perl with normal text and tables.
Now i want to format my table but i can't find the way to do this.
I know to put a format on my table i need to execute following command
$table->AutoFormat(x); with x being e number from 0 to ....
But there are a lot of table styles. I want just a normal one (which is style 16) but i want to assign the border lines and vertical lines myself to create a table by my choosing. Does anyone knew the syntax for this one , or a documentation of the autoformat syntax so that i know which number is which table style
I know this is a question for documentation or tutorials but i searched a lot online and can't find any explanation about the autoformat syntax. And which numbers represet the border or the style . I hope some could help me out here.
You need to look at Microsoft's Visual Basic documentation for the
Word object model.
The OLE interface is simple to understand from there
The page for Table.AutoFormat is here

Accurately Reading Document Content with Position Using Open XML (Word)

I have a need to retrieve a string which matches perfectly the content of a word document. That is to say, in position 1000 of this string, I should find exactly the text at position 1000 in the document.
We have been through various iterations of reading in the document context text and adjusting for field codes/tables/pictures/inline shapes etc by padding in the right places. This approach does work (well) but we want to move towards Open XML instead for speed.
We have Power Tools for Open Xml installed, and have been looking at ways to recreate this string using Open Xml. We can get all the text by going through the runs (as per Eric White's blogs), but we also need everything else. \r's, \t's etc. I see things like "TabChar" in runs, and wdfldChar, but I am unclear how to use this information to generically get what we want.
For example, "TabChar" in our string should be \t. We must need to interpret wdfldChar begin, separate, end in a certain way (maybe by adding spaces). The problem is that we don't want to have to find every possibility and code them
[If run = "TabChar" append."\t" etc] a) because it's inefficient, b) it is unsafe.
Can anyone help with a method to reproduce this string with complete accuracy?
Thanks

Progress 4gl Creating a .xlsx file without excel

Version: 10.2b
I want to create a .xlsx file with progress but the machine this will run on doesn't have excel.
Can someone point me in the right direction about how to do this.
Is there a library already written that can do something like this?
Thanks for any help!
The project was moved to the Free DocxFactory Project.
It was rewritten in C++ with Progress 4GL/ABL wrappers and tutorial.
It is 300x times faster, alot of new features were added including barcodes, paging features etc.
and it's completely free for private and commercial use without any time or feature limits.
HTH
You might find this to be useful: http://www.oehive.org/project/libooxml although it appears that there is nothing there right now. There might also be an older version of that code here: http://www.oehive.org/project/lib
Also -- in many cases the need to provide data to Excel can be satisfied with a Tab or Comma delimited file.
Another trick is to create an HTML table fragment. Excel imports those quite nicely.
A super simple example of how to export a semi-colon delimited file from a temp-table. In 90% of the cases this is enough Excel-support - at least it has been for me.
DEFINE STREAM strCsv.
DEFINE TEMP-TABLE ttExample NO-UNDO
FIELD col1 AS CHARACTER
FIELD col2 AS INTEGER.
CREATE ttExample.
ASSIGN ttExample.col1 = "ABC"
ttExample.col2 = 123.
CREATE ttExample.
ASSIGN ttExample.col1 = "DEF"
ttExample.col2 = 456.
OUTPUT STREAM strCsv TO VALUE("c:\test\test.csv").
FOR EACH ttExample NO-LOCK:
EXPORT DELIMITER ";" ttExample.
END.
OUTPUT STREAM strCsv CLOSE.

Is there a way to detect when a field mark with 'can grow' has truncated the field data?

I do not normally work with crystal, but I have spent nearly 2 days looking for a way to do this.
The problem is that I have a number of lines of text that need to show on a report, but need to cut off after 8 lines and show a 'more' prompt to inform the user that they need to go look at the rest of the details online. This was originally handled by storing the data as individual lines already wrap to size and counting the lines with a formula and conditionally showing a separate 'more' field. They have since added the ability to use html to the text, but this made the current way of doing things wrap incorrectly and show the html mark up.
I wrote a database function to combine the text into a single field and use the HTML text interpretation to display it correctly on 7 other reports that do not limit the text length, and the max line count works great for limiting the text size, I just can't figure out how to show the 'more' prompt when needed.
Any suggestions would be greatly appreciated.
GrumpyGeek,
If your database function now combines the text into a single field does this mean the original way, with the separated lines, is still stored? If so, why not add another calculated field called 'line-count' that tallies the old line-based data?
So you'd still have your new combined HTML field and this new field that you could use to show the 'more' button when 'line-count > x'?
Alternatively, another option might work, but would be a bit touchy. That is to make the formula that shows the more button trigger when the field length exceeds x. The catch is that html mark-up isn't displayed, and heavy use of it would skew the amount of text required before you should show the 'more' button. Put another way, a field with very heavy use of mark-up ( and tags) might force the 'more' button earlier than it should. Unless you could somehow make either your 'line-count' calculated field exclude the mark-up OR make the length calculation do the same.
This would be possible if MSSQL or Crystal Reports could run regex to strip the mark-up.
If NONE of the above works, the only other thing I can suggest is to look into UDFs. Crystal allows you to load an external library that you write. These will read functions you write and show them in the function list inside Crystal. If you do this, then you could easily write a routine that strips the HTML and calculates when the more button should be shown.
Good luck with it.
Ideally, there would be a property of the DB field that would return its displayed line count. Unfortunately, there is no such property.
You could try counting the # of line ending characters (e.g. carriage return, line feed). If they are > 7 then show the hyperlink. In a HTML situation, you have to count ending elements (e.g. ). You could make use of a RegEx UFL to make it easier to identify the elements.
Probably the easiest route is to the DB to calculate the # of lines and return that as another field. Use this field to hide/show the hyperlink.

Highlight pdf line

Please can any one help me. I am really stuck I don't know how to highlight particular line of pdf. It would be better if any one can provide me sample code or pseudo code
Thanks
This is not trivial.
To do this, I'd render the PDF contents into one layer, and somehow get the position of the said line/object using the CoreGraphics PDF parser (or some other way). After that, you highlight the said object using your own drawing code.
Just highlighting a particular line is quite difficult.
If you need search and highlight, please try FastPDFKit. I played with it for a while and it's quite good as a pdf reader.
http://mobfarm.eu/fastpdfkit
I'm working on the same thing at the moment and it's not trivial indeed.
From what I can figure out you need to load the text and arrange it in lines first. If you are using Poppler, the Poppler.Page.textList() will provide you with a list of TextBoxes and a TextBox.hasSpaceAfter() will tell you the end of line when returning False.
I am using the Qt4 frontend, so the each TextBox has a QRect from which I can figure out where to highlight a word. Highlighting a line is more or less lirstWordOfLine.geometry().united(lastWordOfLine.geometry()) which will provide the geometry of the line to highlight.
Now what I can't figure out is how to save the coordinates of the highlights in the document.