Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Exporting DataGrid As Excel

Reply
Thread Tools

Exporting DataGrid As Excel

 
 
batista
Guest
Posts: n/a
 
      10-27-2005
Hi,

I have a web datagrid and i want to give user option
to export it as excel file.

How is it implemented?

Bye.

 
Reply With Quote
 
 
 
 
Tasos Vogiatzoglou
Guest
Posts: n/a
 
      10-27-2005
exportToExcel = function() {
var i;
var j;
var mycell;
var objXL;
try {
objXL = new ActiveXObject("Excel.Application");
if (objXL==null) {
alert("Excel must be installed");
return;
}
}
catch(e){
alert("Error creating Excel ActiveX ");
return;
}
var objWB = objXL.Workbooks.Add();
var objWS = objWB.ActiveSheet;

var tbl = actualTable; // here goes your table object

for (i=0; i < tbl.rows.length; i++) {
for (j=0; j < tbl.rows(i).cells.length; j++) {
mycell = tbl.rows(i).cells(j);
objWS.Cells(i+1,j+1).Value = mycell.innerText;

if ((mycell.innerText.indexOf("/") >= 0) && (mycell.innerText.length
<= 10))
{
objWS.Cells(i+1,j+1).NumberFormat = "dd/mm/yyyy";
objWS.Cells(i+1,j+1).HorizontalAlignment = -4108;
objWS.Cells(i+1,j+1).Font.color = mycell.style.color;
}
}
}

objWS.Range("A1", "L1").Font.Bold = true;
objWS.Range("A1", "Z1").EntireColumn.AutoFit();

objXL.Visible = true;
};

Something like this ...

 
Reply With Quote
 
 
 
 
batista
Guest
Posts: n/a
 
      10-27-2005
thnks for reply,

I have an aspnet datagrid. now at this line

var tbl = actualTable; // here goes your table object

i can get the object of aspdtagrid but how do i access
the rows length, cells length etc in the remaining lines.
I mean js is giving error.

And wat if i want to open a save file dialog when the user
clicks on the excel link.How do i implemet this?

Bye.

 
Reply With Quote
 
=?Utf-8?B?c3Jpbmk=?=
Guest
Posts: n/a
 
      10-27-2005
Hi,
Check this out
http://www.wwwcoder.com/main/parenti...8/default.aspx
--
The best
srini
http://www.expertszone.com


"batista" wrote:

> Hi,
>
> I have a web datagrid and i want to give user option
> to export it as excel file.
>
> How is it implemented?
>
> Bye.
>
>

 
Reply With Quote
 
Tasos Vogiatzoglou
Guest
Posts: n/a
 
      10-31-2005
actualTable = the DOM object representing the table ...
document.getElementById('tableId');

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting to Excel using new version of Excel Doogie ASP .Net 1 11-19-2008 09:10 PM
Exporting the datagrid to excel, text and html files. Ravindra ASP .Net 0 12-14-2005 04:14 AM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia ASP .Net 1 01-12-2005 12:28 AM
Exporting Datagrid's data to an Excel Sheet. http://www.visual-basic-data-mining.net/forum ASP .Net 1 10-25-2004 10:24 PM
Exporting DataGrid to Excel =?Utf-8?B?TmVpbA==?= ASP .Net 2 04-02-2004 11:21 PM



Advertisments
 



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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57