Dynamic column crystal report

Dear All,
I am developing a C# application. So for my crystal report I need to choose a paper size. The problem here is that I want my data column which to appear on my report to be dynamic and I want them to appear dynamically. But due to the paper size restriction I cant go further is there any solution? Thank you.

More like you having a issue placing the column in your report, can you attach a partial screenshot of your report to see what you trying to do?

Dear Lyph,
My requirement is simple just say I got a list of employee. So my column will be each employee name and row will be employee sales data. So when in my C# application I am crystal report to show my report. So in this case when I select a particular paper size it becomes a stopping point for me. How can I overcome this problem ?

If you have say 3 different paper sizes for printing, I would create 3 different crystal reports and dynamically load the crystal report base on paper selection.

Dear Lyn,
So mean that you want my user to select the report based on the paper size options is it. The paper size is also depend on the printer I select. Meaning that in windows application based the paper size is a constraint unlike web based the column is not limited rite? Thank you.

Yes, if you creating the report for website for viewing only, then you can create any size. Only thing you have to consider is when its come to printing.

Dear Lphy,
The problem here I am creating a windows application based on C#. So I am not creating a web base application that is the problem here. So what is the best solution you will suggest for my scenario? I also want the column to appear dynamically meaning that I will have an option say I got 10 employee. I select 5 then only 5 column should appear. How can I do this for crystal report for windows application.

I am little confused about the design you talking about, usually variation parameter should be consider as Rows, Columns should be fixed.

Cannt you change the way you create your report, if you getting varying number of employees, i think its better to design that it should fall as Rows

For example


Name                 Hours Worked     Hourly Pay            Total
Employee1                         35          $17.00          $595.00
Employee1                         42          $18.00          $756.00
....

Like over here, you can change any number of employees but the coulms are fixed.

Dear Lphy,
Sorry for the confusion here. Ok my design will be like this. Each date will show the total sales made by each employee. So any suggestion you have or any idea to solve my problem. Thank you.

Date Employee1 Employee2 Employee3

12/1/09 $200 $500 $600
13/1/09 $560 $400 $700

I think you need to change the way you design your crystal report

If you want to get the total sales for for each day, group by your query with date and show something like this


Date - 10/Apr/2009
                                     Sales
Employee 1                      $500
Employee 2                      $550
Employee 3                      $600
...
                                   ------
Sub Total                        $xxxx

Date - 12/Apr/2009
                                     Sales
Employee 1                      $450
Employee 2                     $650
Employee 3                      $550
...
                                   ------
Sub Total                        $xxxx

....

(footer)Gran Total            $xxxxx

If you want to get the total sales for for employee, group by your query with employee and show something like this


Employee - Employee 1
                                     Sales
10/Apr/2009                     $500
11/Apr/2009                     $550
12/Apr/2009                     $600
...
                                   ------
Sub Total                        $xxxx

Employee - Employee 2
                                     Sales
10/Apr/2009                     $500
11/Apr/2009                     $550
12/Apr/2009                     $600
...
                                   ------
Sub Total                        $xxxx

....

(footer)Gran Total            $xxxxx

Dear Lphy,
Thank you for your idea. Yes I agree your method is good the problem is that if I maintain as my earlier method it gives a me clearer view when I need to compare each employee against each day I mean the tabular format. Thank you.

I think the way basic crystal report design is to keep the columns fixed and maintain rows according to the query. If you want dynamically change number of columns and data at runtime, check this project

http://www.codeproject.com/KB/cs/Dynamic_Crystal_Report.aspx

I would consider generating a Excel work sheet using C# for your case, its much easier.

Dear Lphy,
Yes the excel idea will be great too. Can you teach me how to generate an excel sheet then? Thank you.

There are many ways to do that, I think easiest way is to generate a regular text base HTML string and save it with Excel file extension (.xls)

Example


<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td align="center"><strong>Date</strong></td>
    <td align="center"><strong>Employee 1</strong></td>
    <td align="center"><strong>Employee 2</strong></td>
    <td align="center"><strong>Employee 3</strong></td>
    <td align="center"><strong>Employee 4</strong></td>
  </tr>
  <tr>
    <td>10-Apr-2009</td>
    <td>$500</td>
    <td>$550</td>
    <td>$450</td>
    <td>$650</td>
  </tr>
  <tr>
    <td>11-Apr-2009</td>
    <td>$450</td>
    <td>$600</td>
    <td>$500</td>
    <td>$600</td>
  </tr>
  <tr>
    <td>12-Apr-2009</td>
    <td>$650</td>
    <td>$400</td>
    <td>$650</td>
    <td>$400</td>
  </tr>
</table>

You can generate above HTML string using C# and then save it as a text file with Excel extension. Then you can open it from Excel

Dear Lphy,
I am working on a windows application and not web base application. So I dont think so I can run html codes rite? Thank you.

You can, you can generate any kind of data and save it to disk, it doesnt matter you doing a Desktop application or ASP .Net. Both use the similar method

Dear Lphy,
So how will I generate from my C# code an excel document then off course I need to build the columns and rows too right ? Thank you.

I found this article in Google
Export Sql Table to Excel for Windows Application

Search in google, you will able to find lot of example generating EXcel in C#

Dear Lphy,
Thank you very much for your time. I will look further and incase I got stuck then will get back to you.

Here is another tool might help you to play with dynamic data with crystal report