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!

Exporting Text Files with fixed width fields

Status
Not open for further replies.

eswagerty

Technical User
Mar 16, 2004
3
US
I need some help creating a text file where each field must have a fixed width.

I have been able to create each field to the specified width, but cannot find a way to export it to a text file so that each field stays in its proper place.

If I export the file as a .csv, open it in a text editor and delete the "," seperators between fields, I get the result I need.

Does anyone know a way to get the fields to export, one after another without spaces, as a text file? I would like to give this to another person and not make them edit it in a text editor.

Thanks,
eswagerty
 
I tried Record style (no spaces) but crystal reports puts spaces between the fields. It looks like the inserted spaces are based on the way the fields are layed out in design view.

Do you know a way to export them so the next field starts immediately after the previous one ended?
 
I don't know what about your layout is causing these spaces.

If you can't find a way to achieve the desired output using Crystal exports, consider using one of the UFL's that allow you to use formulas in Crystal to create and write to a text file.

There's a list of 3rd-party tools at:

Two relevant UFLs that I'm aware of are the "Disk File" UFL at:
and my "CUT Light" UFL at:

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Does report layout normally effect Record Style (no spaces) exports?

I am exporting one group footer line where the fields are placed on the report as close as possible to one another without overlapping.

Thanks,
eswagerty
 
I'm trying to do the same thing and I'm using the Record Style(No spaces). However my issue involves every record being exported even though I have the details section suppressed. The data that I am displaying is in a group footer as I only want the last record to display for the group. Displays fine to the screen however upon export every record is exported.

Any advice would be greatly appreciated.
 
Have you tried exporting as Excel? And then from Excel as something else?

Madawc Williams (East Anglia)
 
You could try something like this.

-For each field to be exported, create a formula that will "pad" spaces on the end so that you have the length that you want. For example:
Code:
{@Field1}
left({table.field1} + ReplicateString(' ',30), 30)
This will give you a value that's guaranteed to be 30 characters, right-filled with spaces.

-Put a Text object on the report and expand it to the width of the report.

-Put each of your formulas in the text object, one after the other with no spaces in between.

-Turn off 'Can Grow' for the text field.

-Dell
 
Doesn't appear that exporting a text object works. Data shows properly on the report, but when exporting using the text export the file is blank.

Rhonda
 
What version of Crystal are you using? How long is the text record? There are constraints on this, I think it's 254 characters or something, but what I do is build one big formual, appending each 'field' in the formula with appropriate spacing, formatting, etc., and then dump the whole formula into a text box on the reports.


First, make a separate formula called padSpaces (or something):

@padSpaces
stingvar padSpaces:=space(200);
padSpaces;

now, in your record making formula....

stringvar myString:="";


mystring:=
left({myTable.myField1} + {@padSpaces}),35) + //for a field that needs to be 35 positions
left({myTable.myFiled2} + {@padSpaces}),20) + //for a field that needs to be 20 positions
left({myTable.myField3} + {@padSpaces}),50); // 50 position field
//etc

myString:=UCase(myString); //Makes the whole string upper case, useful for
//financial institutions, 401K's, government reporting, etc.

myString;

Using the left function with the padSpaces formula variable lets you take whatever is in the field, and pad it with enough spaces to make it n postions long, without screwing around and counting the lenght of the text in the field, subtracting, blah blah blah.

Then when you're done, you make a text box on the report and put the @myString formula into it.

One final thing, if your record is longer than the page size you're working with, you MUST shrink down the page view to like 25%, grab right edge of the text box, and stretch it out PAST the page margin. Otherwise, Crystal will feed a carriage return during the output where the page wraps.

Let me know if you need clarification, this looks screwy, but honest, I do it all the time.
 
reporter42 said:
Doesn't appear that exporting a text object works. Data shows properly on the report, but when exporting using the text export the file is blank

Have you tried exporting as a plain text file using the text objects instead of as CSV or Record?

-Dell
 
I did end up using the plain text file as I ran into problems with the Record Style export.

The last issue that I had with it was that at a certain point the data exported would just quit at a certain place. I can't remember what position exactly, but I got around it by placing the last few fields in a text object and this worked.

The only issue that I had remaining was that the last field wasn't a fixed length. The end of the record was always right after the last character in the field. The spaces at the end to fill out the field were ignored. The hint that Pajon has above may fix that though, so I'm going to try that.

I liked the idea of the record style export as it would do exactly what I want, however, I ran into an issue when the data you want to export was derived either by conditionally suppressing detail lines or by putting the data in a group header or footer. The Record Style export isn't paying attention to conditional suppression or surpression of sections. A record is being displayed for all data, not just the group or the data being displayed to the screen. So if I have 3 detail records, but I have a summary of them in a group footer and the detail section is suppressed, the summary displays fine to the screen, but when exported it exports the group summary 3 times.

Exporting as text works well (I do remember that I had to download a monthly hotfix), but I did have the issue as explained earlier.

Thanks for your help.

-Rhonda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top