Toon posts:

[C# web + excel] export naar excel

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb een datagrid geexporteerd naar een excel sheet.
Wat is het probleem, ik wil extra info dat niet in de datagrid staat ook in de sheet.

op de 3e cel begint de header van het grid:
ss.ActiveSheet.Cells[3,colnr] = dgc.HeaderText.Replace("<br>"," ");
de 2e cel moet leeg zijn en op de 1e cel moet naam komen te staan.
En heb dat vervolgens zo gedaan:
ss.ActiveSheet.Cells[1,colnr] = "Naam:";

Ik krijg dan echter de foutmelding dat de parameter incorrect is.
Hoe krijg ik het dan toch voor elkaar dat gegevens buiten de datagrid in een excel sheet worden gezet?


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public static void DataGridNaarExcel (DataGrid dg, string filename, Page pagina)
{
int colnr = 0;
OWC.Spreadsheet ss = new OWC.Spreadsheet();
for (int col = 0; col < dg.Columns.Count; col ++)
{
    DataGridColumn dgc = dg.Columns[col];
    if (dgc.HeaderText != "")
    {
    colnr ++;
    ss.ActiveSheet.Cells[3,colnr] = dgc.HeaderText.Replace("<br>"," ");
    for (int row = 0; row < dg.Items.Count; row ++)
    {
        DataGridItem dgi = dg.Items[row];
    if (dgc.ItemStyle.HorizontalAlign == HorizontalAlign.Right)
    {
    // numeriek veld!!!!
                            ss.ActiveSheet.Cells[row+2,colnr] = Double.Parse (dgi.Cells[col].Text);
                }
    else
    {
                            ss.ActiveSheet.Cells[row+2,colnr] = "'" + dgi.Cells[col].Text.Replace("<br>", " ");
                        }
                    }
                }
            }
            ss.ActiveSheet.Columns.AutoFitColumns();
            string path = System.Configuration.ConfigurationSettings.AppSettings["export_file_path"].ToString()+"xls/";
            string virtpath = System.Configuration.ConfigurationSettings.AppSettings["export_virtual_path"].ToString()+"xls/";
            ss.ActiveSheet.Export(path+filename,OWC.SheetExportActionEnum.ssExportActionNone);
            DownloadFile (virtpath+filename,true,pagina);
        }