Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reformat document into canned report?

Status
Not open for further replies.

greif1

IS-IT--Management
Sep 26, 2005
87
US
Reformat document into canned report?

I need to have a program that I can input a text document that is always in exactly the same format (spacing, columns, etc) and output selected bits of this in a good looking report.

Ideally, have unlimited ability to place text anyplace I want in a template reformatted from the original position.

A little calculation ability and ability to add some fixed text to the final document would be a plus.

Anybody know of anything like this?
gr
 


Hi,

What application and version?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That's both the problem and the simplicity of it all. The text document is produced by an ancient HP Instrument basic analysis system. A pretty report needs to be generated from this plain text document. The software which would convert this should run on WinXP. I am looking to have it pretty canned and cut and dried so an operator can follow a few steps and have a pretty document come out with minimal handwork.
 


What application and version of MS OFFICE are you using or plan to use?

What kind of DOCUMENT do you want?

Is the source data tabular, prose, graphics?????

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
We have a variety of Office installations from 97-2003. Working in the oldest would be great, but I can get the newest (2007) to run this in if needed.

A Word document as output would be nice. Excel would work too. I plan on having a small graphic logo at the top of the report, but the rest is just text.

The source data is a text file. Plain old Ascii type text.
With an old fashioned 8.3 file name.
It is normally 2 or 3 pages long.
It (in part)looks like;

06-25-2009, 2:06:45 PM, xxxxxx, xxxxxxxx = 6 mils, window =

6 Random File(s) Starting with t051
Parameters

Scan# 1. 2. 3. 4. 5. 6. Scan#

#elem 59 59 59 59 59 59 #elem
SC 506 504 502 742 745 742 SC
MEC 438 437 435 644 643 644 MEC
ERNS 10 17 13 226 221 227 ERNS
ERNB 13 0 0 0 0 0 ERNB
ERNQZ 10 17< 13< 0 9 8 ERNQZ
LEADQZ 1 1 1 1 1 1 LEADQZ
TRLQZ 1 1 1 1 1 1 TRLQZ
Format 15B 15B 15B 15B 15B 14B Format
Rxxx 84 84 85 90 90 93 Rxxx

 


Either could work.

It the data mostly tabular or not?

Are there multiple tables?

You're probably going to need some VBA code to effect a repeatable solution.

But YOU need to decide which way to go.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
It [sic] the data mostly tabular or not?
Are there multiple tables?"

The tabular or not is critical. I suspect not, but we need to know. I suspect there are no tables at all; that it really is plain-text.

"and output selected bits of this in a good looking report."

YOU must define what is meant by "selected bits". Do you mean actually selected with the mouse? Some sort of pre-determined chunks? What?

I am sure something could be achieved, but you must determine exactly what that will be.

Gerry
 
I shall try to answer the various questions;
1) No tables, plain text, ACSII style text only.
2) No tabs (I think)
3) Pre-determined chunks of text selected and reformated into a Word or Excel, or even another plain text document.This would be a permanent set of predetermined chunks for each specific report. The final user will not have to select text, just run something to convert the document.

I had hoped something would be available that would work in a grid format, where the text in the original document was gridded, and those grid coordinated were specified on the second document to reformat it.
 
What I posted was not a table, just plain text in what is normally in columns (got moved around in copying to this venue).

Are we talking two different things? I think table as in MS Word. Do you mean something else?
gr
 
Skip, it is as I suspected...no tables. It just looks like a table.

It is VERY important to know if those spaces:

#elem 59 59 59 59 59 59 #elem

are just spaces, or tabs. Again, I suspect not.

"2) No tabs (I think)"

Be sure. Turn on Show/Hide. If they are tabs, they will show as tabs (little arrows).

So, OK, it comes down to: "3) Pre-determined chunks of text selected "

Forget about the "selected" part. It is the pre-determined that is significant. Properly done, there should be no need to select anyway at all.

"I had hoped something would be available that would work in a grid format"

As there are no tables...there is no possibility of any grid. It is plain-text...no grid.

What is also crucial to know is if these are lines terminated by paragraph marks. Again, turn on Show/Hide and see. If they are (and it is very possible they are NOT, because this is an old plain-text output) it makes things easier. If they do NOT terminate with paragraph marks, it can still be done, but it becomes trickier.

Bottom line is as has been stated. YOU must determine what are those chunks. Here is an example:
Code:
Option Explicit

Sub Yaddagerry()
Dim rDoc As Range
Dim rChunk As Range
Dim j As Long
[COLOR=red]' set document range object[/color red]
Set rDoc = ActiveDocument.Range
With rDoc.Find
    [COLOR=red]' find FIRST #elem[/color red]
    .Text = "#elem"
    .Execute
    [COLOR=red]' set chunk range object to the START of first "#elem"[/color red]
    Set rChunk = ActiveDocument.Range( _
        Start:=rDoc.Start, _
        End:=rDoc.Start)
    [COLOR=red]' collapse document range[/color red]
    rDoc.Collapse 0
    [COLOR=red]' reset search to "ERNS"[/color red]
    .Text = "ERNS"
    [COLOR=red]' search twice to find SECOND "ERNS"[/color red]
    For j = 1 To 2
        .Execute
    Next
    [COLOR=red]' set chunk ranage object .END to end of
    ' second "ERNS"[/color red]
    rChunk.End = rDoc.End
    MsgBox rChunk.Text
End With
End Sub
This would make a range object equal to the text between the FIRST "#elem" and the SECOND "ERNS".

06-25-2009, 2:06:45 PM, xxxxxx, xxxxxxxx = 6 mils, window =
6 Random File(s) Starting with t051
Parameters
Scan# 1. 2. 3. 4. 5. 6. Scan#

[highlight]#elem 59 59 59 59 59 59 #elem
SC 506 504 502 742 745 742 SC
MEC 438 437 435 644 643 644 MEC
ERNS 10 17 13 226 221 227 ERNS[/highlight]
ERNB 13 0 0 0 0 0 ERNB
ERNQZ 10 17< 13< 0 9 8 ERNQZ
LEADQZ 1 1 1 1 1 1 LEADQZ
TRLQZ 1 1 1 1 1 1 TRLQZ
Format 15B 15B 15B 15B 15B 14B Format
Rxxx 84 84 85 90 90 93 Rxxx

Again, once you actually determine what those "pre-determined' chunks are, then you can do it.

Gerry
 
If you tack the following on after fumei's last End With you should have an example that demonstrates how to turn the chosen range into a Word table
Code:
[blue]With rChunk
    .Find.ClearFormatting
    .Find.Replacement.ClearFormatting
    With .Find
        .Text = " @<"
        .Replacement.Text = "^t"
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    .Find.Execute Replace:=wdReplaceAll
    .ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=8, NumRows:=12, AutoFitBehavior:=wdAutoFitFixed
    With .Tables(1)
        .Style = "Table Grid"
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
    End With
End With[/blue]
 



There MAY be SPACES between, but the FORM of that body of data is TABULAR. SPACES or TABS can be a result of the output method. I could care less ;-)

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
YOU may care less (as I do as well), but as the issue is some sort of formatting of chunks...Word - as much as any application CAN "care" - does care.

However Skip, you are (I think) correct, in that it looks tabular, and one would assume the OP would like to retain some sort of tabular structure. Whether that is an actual table, or not, is not known. However, as there also appears to be a request for some calculation ability, then yes, it most likely should go into a table.

Or better yet, into Excel. Although, as it is primarily text, I would be against that.

The OP must define their pre-determined chunks, and clearly define their actual requirements.

Gerry
 

The OP must define their pre-determined chunks, and clearly define their actual requirements.
That THAT is the purpose of the probing questions. Is this more tabular with annotations or texual with a scattering of tabular?

Please do not interpret this as textual harassment.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
>Whether that is an actual table, or not, is not known

Load the example data into Notepad with a fixed font and you will see that it is a table. It's pretty clear.
 
Load the example data into Notepad with a fixed font and you will see that it is a table. It's pretty clear. "

I did - I am looking at it at this very moment - and I hate to disagree...but I do. Although that could be due to a difference of what we separately may consider a "table".

Assuming (and that may or may not be an truly accurate assumption) that the OP copied directly from the source file, and that what we can copy from HERE, for example:

ParametersScan# 1. 2. 3. 4. 5. 6. Scan#

The above is copied dirtectly from the post of 19 Nov. Notice that Scan# follows Parameters, no space. HOWEVER, in the thread, it "looks like":

Parameters

Scan# 1. 2. 3. 4. 5. 6. Scan#

At least on my monitor. Which, to me, looks like "Parameters" (one line), a spacer line/paragraph, then "Scan#...."

In the real source file, which is it?

Further, in the original posting:

ERNS 10 17 13 226 221 227 [highlight]ERNS ERNB[/highlight] 13 0 0 0 0 0 ERNB ERNQZ 10 17< 13< 0 9 8 ERNQZ LEADQZ 1 1 1 1 1 1 [highlight]LEADQZTRLQZ[/highlight] 1 1 1 1 1 1 TRLQZ

appears as:

ERNS 10 17 13 226 221 227 ERNS
ERNB 13 0 0 0 0 0 ERNB
ERNQZ 10 17< 13< 0 9 8 ERNQZ
LEADQZ 1 1 1 1 1 1 LEADQZ
TRLQZ 1 1 1 1 1 1 TRLQZ

which of course does look like a table. However, in my mind it is NOT a table. In the original, the start of the "ERNB" line has two spaces (and a manual line break NOT a paragraph mark) following the proceeding "ERNS" termination.

But the start of the "TRLQZ" lines does NOT have three (or any) spaces following the "LEADQZ" termination.

In other words, there is not a consistency in the "tabular" structure.

THREE spaces between SC and MEC "lines"
TWO spaces between ERNS and ERNB "lines"
ONE space between ERNQZ and LEADQZ "lines"
NO space between LEADQZ and TRLQZ "lines"

Are these significant? Are they part of the "table" structure? Should they be?

There are, in fact, no tabs in the text, so I am wonder hopw you can call it tabular. And it only looks like a table in Notepad if you size the Notepad window to make it look like one.

I believe, however, it may be a moot point. The OP wishes to extract chunks, which can be set up via text strings. It would be fairly easy to make the text into a table, as strongm as already shown. But I disagree that it IS a table, as it stands. At least as far as a Word table.

Gerry
 
>Although that could be due to a difference of what we separately may consider a "table".
>But I disagree that it IS a table, as it stands. At least as far as a Word table
>no tabs in the text, so I am wonder how you can call it tabular

Indeed. You seem to think that only a Word table is a table. And that a table needs to have tabs. Both of these are patently untrue. Below has no tabs, and we are clearly not in Word so it cannot be a Word table, but it is definitely a table ...

[tt]Month Sales Men
Dec 1000 Mike
Nov 12681 David
Aug 234 Tim [/tt]

> And it only looks like a table in Notepad if you size the Notepad window to make it look like one

Given the above, and your other examples of strange layout in Notepad I'm betting that you are using IE8, Gerry. It isn't completely compatible with the HTML generated by tek-tips, and ignores a number of HTML tags when copying and pasting (<BR /> being one of them). Might I suggest that you switch to compatibility view (Tools/Compatibility View), and then copy and paste the data in Notepad again (and make also switch off Notepad's word wrap feature)...

This is what the post of 19th Nov looks like to me in Notepad:

[tt] 06-25-2009, 2:06:45 PM, xxxxxx, xxxxxxxx = 6 mils, window =

6 Random File(s) Starting with t051
Parameters

Scan# 1. 2. 3. 4. 5. 6. Scan#

#elem 59 59 59 59 59 59 #elem
SC 506 504 502 742 745 742 SC
MEC 438 437 435 644 643 644 MEC
ERNS 10 17 13 226 221 227 ERNS
ERNB 13 0 0 0 0 0 ERNB
ERNQZ 10 17< 13< 0 9 8 ERNQZ
LEADQZ 1 1 1 1 1 1 LEADQZ
TRLQZ 1 1 1 1 1 1 TRLQZ
Format 15B 15B 15B 15B 15B 14B Format
Rxxx 84 84 85 90 90 93 Rxxx
[/tt]

>In other words, there is not a consistency in the "tabular" structure

Au contraire. Clearly the HP output is allowing 6 characters for that final column; it is completely consistent:

FOUR (not three) spaces between SC and MEC "lines": SC + 4 = 6 Characters
TWO spaces between ERNS and ERNB "lines": ERNS + 2 = 6 characters
ONE space between ERNQZ and LEADQZ "lines": ERNQZ + 1 = 6 characters
NO space between LEADQZ and TRLQZ "lines": LEADQZ = 6 characters

And thus the answers to your questions: Are these significant? Are they part of the "table" structure? Should they be? are yes, yes and yes
 
What makes:

Month Sales Men
Dec 1000 Mike
Nov 12681 David
Aug 234 Tim

a table?

"You seem to think that only a Word table is a table."

Not at all. I think I have been clear.
But I disagree that it IS a table, as it stands. At least as far as a Word table.
The fact is we are talking about processing text strings in Word. Not Notepad or anything else. So that is what I have been talking about. Word.

Yes, you could do a character count to determine the table structure in Word.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top