Re: export dataset to excel in winform

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

Take a look at this code, I'm using it and works great,
http://support.microsoft.com/default.aspx?scid=kb;EN-US;316934

Now, I do not need to create an excel table, I have embedded in my .EXE an
empty excel file with the format I need

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Hans [DiaGraphIT]" <hans.arsjo@xxxxxxx> wrote in message
news:89CBF363-6655-417D-B698-04AF205D7571@xxxxxxxxxxxxxxxx
> Hi!
>
> I want to export a dataset to an excel file. I found following code on
> the
> net...
> ( http://www.codeproject.com/csharp/Export.asp )
>
> Excel.ApplicationClass excel = new ApplicationClass();
>
> excel.Application.Workbooks.Add(true);
> DataTable table = DATASETNAME.Tables[0];
> int ColumnIndex=0;
> foreach(Datacolumn col in table.Columns)
> {
> ColumnIndex++;
> excel.Cells[1,ColumnIndex]=col.ColumnName;
> }
> int rowIndex=0;
> foreach(DataRow row in table.Row)
> {
> rowIndex++;
> ColumnIndex=0;
> foreach(DataColumn col in table.Columns)
> {
> ColumnIndex++;
> excel.Cells[rowIndex+1,ColumnIndex]=row.Cells[col.ColumnName].Text;
>
> }
> }
> excel.Visible = true;
> Work*** work*** = (Work***)excel.Active***;
> work***.Activate();
> )
>
>
> I asume that this code will work just fine for me, but how do I include an
> applicationclass for Excel?
>
> Do I need to include an excel.dll file for this occasion, and if so where
> do
> i find this dll fie?
>
>
> ---------------
> Best regards
> - Hans -
> ---------------
> (Have fun programming with ... C#)


.


Quantcast