473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Exporting DataGrid As Excel

Hi,

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

How is it implemented?

Bye.

Nov 19 '05 #1
4 986
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 ...

Nov 19 '05 #2
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.

Nov 19 '05 #3
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.

Nov 19 '05 #4
actualTable = the DOM object representing the table ...
document.getElementById('tableId');

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Neil | last post by:
Hi I'm currently exporting my datagrid to excel, taking advantage of the fact that excel can render html, the problem is that when i click the button to export it opens in browser, I want the button...
2
by: Michael | last post by:
I need to be able to export data from a web form into MS Excel. I know you can do it with a VB.net windows application, but how can you do it with an asp.net application using vb.net? Any help...
1
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But it always use the web form's name as the default...
4
by: Hitesh | last post by:
Hi, I have three datagrid control on my aspx page and one export to excel button, i want to export all the 3 datagrids contents in one excel file. how can i achive that? -- Thanks Hitesh
1
by: NancyA | last post by:
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) dg.RenderControl(hw)...
7
by: Stephen Noronha | last post by:
Hi, I found an very interesting article on converting Datagrids to Excel. I apologize that I forgot the name of the author/article but it was very helpful. Problem: it converts only the...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
6
by: Opa | last post by:
Hi, I have a DataGrid, whose sourceI am exporting to Excel. This works fine except for the Column ordering. My datasource is not a datatable, with a typical SELECT statement where I can...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name to the excel file as "temp.xls" inside the code....
0
by: kanepart2 | last post by:
Hi , I have the following code to export a datagrid to excel Public Sub ExportToExcel(ByVal dt As DataTable) Try Dim oApp As New Excel.Application Dim oBook As Excel.Workbook =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.