Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show the contents of a text file in Crystal Reports

Tags:

I have a crystal report which contains a list of absolutely referenced text files. There is one text file referenced in each body line.

e.g.

line1    c:\file1.txt
line2    c:\file2.txt

Is there any way to display the contents of these files in Crystal?

i.e. I would like each crystal body line to show the text from the referenced text file.

I'm using Crystal reports 11 with a non-standard database connector (dataflex).

like image 475
seanyboy Avatar asked Jun 22 '09 14:06

seanyboy


2 Answers

You would need to set up a file dsn (in XP it's under Control Panel/Administrative Tools/Datasources (ODBC)) and then use the file dsn (Microsoft Text Driver) for the datasource as an ODBC(RDO) connection.

I set this test scenario up on mine like the following:

**File 1**
column1
1row1
1row2
1row3

**File 2**
column1
2row1
2row2
2row3

I set up the file dsn to point to the c drive and in the datasource screen I added file1.txt and file2.txt to the selected tables. Then the easiest thing to do is clear the links of the tables so that it pulls every row. It will warn you that there are multiple starting points. I don't generally recomend this, but it will work in this case and since it's not reporting off a database it probably isn't the end of the world. If you disregard the starting point message then add the fields to the report, when you run it you should get the following output:

1row1     2row1
1row1     2row2
1row1     2row3
1row2     2row1
1row2     2row2
1row2     2row3
1row3     2row1
1row3     2row2
1row3     2row3

From this you can change your grouping to get the output that you need.

You can also use this same connect against subreports instead of doing this linking where you have the main report pull the info from file1.txt and then put a subreport in the report footer that pulls from file2.txt. This option won't have the text collated, but you'd still have it in the same report.

Hope this helps some.

like image 130
Dusty Avatar answered Oct 12 '22 04:10

Dusty


It's easier than you think. I just set up one myself before I wrote this to make sure I was giving you the right steps. Using CR version XI and a .txt file, I followed these steps:

  1. For each text file you want to import, make a subsection in your report (i.e. DetailsA, DetailsB, etc.). If your list of text files is constantly changing (and I don't think it is, based on your description), you'll need another method.
  2. Make sure your text file is comma delimited and the first row contains field names. If these text files are actually text (i.e. not tables), then just put a dummy variable name in the first row so Crystal will see the text as a table of data with just 1 row.
  3. For each text file you want to display, create a new Subreport (Insert->Subreport)
  4. In the database selection menu, go to "Create New Connection"->"Access/Excel (DAO)"
  5. Under 'database type', you'll see a 'text' option at the bottom of the screen.
  6. Choose your file.
  7. Relax! (I'm in a good mood this morning, don't know why)
like image 32
PowerUser Avatar answered Oct 12 '22 03:10

PowerUser