 |
|
|
 |
|
 |
Hey Niru Do You have that code in vb now to export datagrid into excel file.. if it is with you please provide me. thanks Ravinder Singroha
Thanks & Regards, Ravinder Singroha
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Is it possible to change the format without looping through each row. If I have 100 columns and 50 K rows , then looping through each cell is an overhead right? How can I do this without looping. Cant i set this value for the whole column or something like that? Thanks Soni
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
You can check out the following article in which I explained many different things related to GridView export to excel.
http://highoncoding.com/Articles/197_Extensive_Study_of_GridView_Export_to_Excel.aspx
Mohammad Azam azamsharp@gmail.com www.highoncoding.com Houston, TEXAS
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I know this a pretty old post but I just found it. I adapted this code to format all cells as a string and didn't do any looping. For my needs, this ended up being much faster... I'm just passing this along in case it helps someone:
Instead of just a normal "Response.Write(sw.ToString());" , I replaced it with this:
string StyleAsText = @"<style> .StyleAsText { mso-number-format:\@; } </style> "; Response.Write(StyleAsText + sw.ToString().Replace("<td>", "<td class='StyleAsText'>"));
Good luck!
A. Soong
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | Help  Saranya.Zy | 21:42 1 Mar '09 |
|
 |
i need to export three datagrid's content and some other content in to single excel sheet.May i know how to do this?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have used the following code to export my datagrid to excel:
Private Sub Export_Click(ByVal Src As Object, ByVal e As EventArgs) Handles _Export.ServerClick If Page.IsValid Then If OnExport() Then 'Response.Write("<Script language=JavaScript>alert('" & rm.GetString("opsucess") & "');</Script>") there is some problem in Edit Subscriber screen for accessing Resource Manager Response.Write("<Script language=JavaScript>alert('Operation Successful');</Script>") 'Page_Reset() 'Page_Clear() End If End If End Sub -----------------------------------------------------------------------
Protected Function OnExport() As Boolean Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.xls" Dim stringWrite As New System.IO.StringWriter Dim htmlWrite As New HtmlTextWriter(stringWrite) htmlWrite.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Html) 'this.ClearControls(reportGrid) _Grid.RenderControl(htmlWrite) htmlWrite.RenderEndTag() Response.Write(stringWrite.ToString()) Response.End()
Return True End Function
--------------------------------------------------------------------- Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
-------------------------------------------------------------------------- I have an .aspx page and corresponding code behind vb page inherited from the page containing the above code. the Export button and the grid are also being inherited from here .Earlier i was not using the 'VerifyRenderingInServerForm' and i was getting an exception on the statement : _Grid.RenderControl(htmlWrite) now after using
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
the exception is gone .i am able to save the excel file but without the dynamic contents of the datagrid.it just displays crosses all over the excel file where there was data in the grid. how do i get the complete data.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
This solution does not seem to work for me all the time...I am applying the style (see below) the only problem is that it is still exporting the bottom portion of the column as text not number...(it was always doing that)
Private Sub gvResults_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvResults.RowDataBound
Dim ea As GridViewRowEventArgs ea = CType(e, GridViewRowEventArgs) If (ea.Row.RowType = DataControlRowType.DataRow) Then For Each c As TableCell In ea.Row.Cells If IsNumeric(c.Text) Then c.Attributes.Add("style", "mso-number-format:#;") End If Next End If End Sub
Here is something that should also be noted...if I export the same rows with 2 columns instead of the original 28 columns then (column #1, where the numbers are) is picked up by excel as numeric.
I really need help with this...I have already invested about 10 hours with this.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This is not the correct way of exporting to excel format. What u r doing is exporting to html format and naming the file as .xls, the format is not excel's binary format.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
From a web application this is the correct way to export the data to excel. Yes we are exporting to HTML format and naming the file as .xls but Excel has the power and functionality to read the HTML file and display it properly.
Mohammad Azam azamsharp@gmail.com www.gridviewguy.com www.screencastaday.com Houston, TEXAS
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
the following code exports a datagrid to excel, but here is the problem, when opening in Office 2007 it give an error that that states -
The file you are trying to open is a different format than than specified by extension, Verify that the file is not corrupt and is from a trusted source before opending the file. Do you wnat to open now. If I open it it works just fine and can then save to new format.
When I open it opens fine but users might get the wrong impression that its messed up. here is the code I am using. how can I fix this so that if users are suing either version of Office, 2003 or 2007 it will open and save properly.
Here is my code...thanks in advance...
protected void Button4_Click(object sender, EventArgs e) { Response.Clear(); string filename1 = TextBox3.Text; Response.AddHeader("content-disposition", "attachment;filename=" + filename1 + ".xls"); Response.Charset = ""; Page.EnableViewState = false; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmwrite = new HtmlTextWriter(stringWriter); DataGrid1.RenderControl(htmwrite); Response.Write(stringWriter.ToString()); Response.End(); }
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
 | Thanks  nellairahul | 18:40 26 Feb '09 |
|
|
 |
|
 |
Hi In a project iam having two pages named page1.aspx and page2.aspx in both the pages i want to export to word so i bound to a dataset to a datagrid and i export by this code
Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.doc"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDataGrid.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End();
here in from page1.aspx is working but it is not working in page2 can any one help me
Boobal
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Hi Experts,
I am trying to export content of TableCell control to excel file. I got a problem with unicode character (ex. €) - it is converted to "€" in excel file. I read posts regarding unicode characters and copied the code, however it still can not be displayed. Please HELP!!!!!
1). Definition of TableCell: <asp:Table ID="tbl" runat="server" Width="100%"> <asp:TableRow> <asp:TableCell ID="tblCell" runat="server ></asp:TableCell> </asp:TableRow> <asp:Table> 2). Populate tableCell Dim XmlPackage As New XmlDocument Dim XslDoc As New Xsl.XslCompiledTransform Dim xslArgs As New Xsl.XsltArgumentList Dim settings As New System.Xml.Xsl.XsltSettings Dim htmlText As New Text.StringBuilder Dim textWriter As New IO.StringWriter(htmlText)
XmlPackage.LoadXml(dataset.GetXml()) settings.EnableDocumentFunction = True XslDoc.Load(Server.MapPath(ResolveUrl("table.xsl")), settings, New XmlUrlResolver()) XslDoc.Transform(XmlPackage, nothing, textWriter) tblCell.Text = htmlText.ToString() 3). Export to excel: Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.xls"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter() Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite) stringWrite.Write("<html><head><meta http-equiv=\""content-type\"" content=\""text/html; charset=utf-8\""></head><body>") tblCell.RenderControl(htmlWrite) stringWrite.Write("</body></html>") Response.Write(stringWrite.ToString()) Response.End()
Thank you very much for your help!
|
| Sign In·View Thread·PermaLink | 4.00/5 |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi, I am trying to Export a datagrid to an Excel. But once the No.of rows in the excel exceeds 30,000, i am getting Memory exception error. Any idea how this problem can be sorted.?
My data grid will have atleast some 60,000 rows.
I am using the below mentioned coding in my function.
Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDataGrid.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End();
Regards, R Sukanya
|
| Sign In·View Thread·PermaLink | 1.33/5 |
|
|
|
 |
|
 |
I know how I can export multiple datagrids but when I do that they appear in Excel like this:
DataGrid1 DataGrid2
What I need is:
DataGrid1 DataGrid2
since they look like this on the asp.net page like this too
|
| Sign In·View Thread·PermaLink | 2.75/5 |
|
|
|
 |
|
 |
I am getting an error, Server cannot append header after HTTP headers have been sent. I am trying to download a file from ftp server. I have a grid which displays the list of files and when the user selects one, I open a pop-up where the download occurs in page_load.It is working fine but when I try to show an image while the download process is going on as it is otherwise shown as a blank page, I get the above mentioned error.
/*****************Code for image display**************************/ const string MAIN_IMAGE = "/_layouts/images/novartis/waiting.gif"; const int PROGRESS_BAR_SIZE = 10; //number of steps in your progress bar const string PROGRESS_BAR_STEP = "/_layouts/images/novartis/pik.gif"; //image for idle steps const string PROGRESS_BAR_ACTIVE_STEP = "/_layouts/images/novartis/pik.gif"; //image for active step Response.Write(""); Response.Write("<img src="\""" main_image="">"); Response.Write(" "); for (int i = 1; i <= PROGRESS_BAR_SIZE; i++) { Response.Write("<img id="pro" + i.ToString() + "" src="" + PROGRESS_BAR_STEP + ""> "); } Response.Write("</img> "); Response.Write("</img> "); Response.Write("<script language="javascript">"); Response.Write("var counter=1;var countermax = " + PROGRESS_BAR_SIZE + ";function ShowWait()"); Response.Write("{ document.getElementById('pro' + counter).setAttribute(\"src\",\"" + PROGRESS_BAR_ACTIVE_STEP + "\"); if (counter == 1) document.getElementById('pro' + countermax).setAttribute(\"src\",\"" + PROGRESS_BAR_STEP + "\");else {var x=counter - 1; document.getElementById('pro' + x).setAttribute(\"src\",\"" + PROGRESS_BAR_STEP + "\");} counter++;if (counter > countermax) counter=1;}"); Response.Write("function Start_Wait(){mydiv.style.visibility = \"visible\";window.setInterval(\"ShowWait()\",1000);}"); Response.Write("function Stop_Wait(){ mydiv.style.visibility = \"hidden\";window.clearInterval();}"); Response.Write("Start_Wait();</script>"); Response.Flush();
/**************Code for download**********************/
if (Request.QueryString["DownloadUrl"] != null) { FtpWebRequest reqFTP; //HtmlControl frame1 = (HtmlControl)this.FindControl("frame1"); //frame1.Attributes["src"] = "Iframe1WebForm.aspx"; try { string fileName = Request.QueryString["DownloadUrl"].ToString(); string filename = Path.GetFileName(fileName); WriteLog(filename); Response.Buffer = true; Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.ContentType = "application/octet-stream"; ////Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.Flush(); reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + filename)); WriteLog(reqFTP.RequestUri.ToString()); reqFTP.Proxy = null; reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword, ftpDomain); //WebResponse aa = reqFTP.GetResponse(); FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Stream ftpStream = response.GetResponseStream(); MemoryStream MemStream = new MemoryStream(); int bufferSize = 102400;//2048; byte[] respBuffer = new byte[bufferSize]; try { int bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length); WriteLog("byteRead" + " " + bytesRead.ToString()); while (bytesRead > 0) { MemStream.Write(respBuffer, 0, bytesRead); bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length); WriteLog("inside while" + bytesRead.ToString()); } byte[] finalByte = MemStream.GetBuffer(); Response.BinaryWrite(finalByte); } finally { ftpStream.Close(); response.Close(); } } catch (Exception ex) { throw ex; }
|
| Sign In·View Thread·PermaLink | 1.67/5 |
|
|
|
 |
|
 |
I have a similar issue. I am currently exporting a data grid from a ASP.NET app and I have 3 numeric/currency fields in it, when exported to excel it comes up as currency type but stored in the excel cell as text. The actual tool tip of the cell says "The number in this cell is formatted as text or preceded by an apostrophy". I am using:
response.Write("<style> .CurrencyLabel" + "\r\n" + "{mso-style-parent:style0;mso-number-format:\""+@"\0022$\0022\#\,\#\#0\.00"+"\""+";} " + "\r\n" + "<style>;");
in if I save the excel file as a htm file and view it in notepad I can see:
.xl27 {mso-style-parent:style0; color:black; mso-number-format:"\0022$\0022\#\,\#\#0\.00"; border:.5pt solid black;}
so I know the number format is going in fine, but when I open it up I get the issue with a hidding character being in front of those columns. If I click a individual cell and backspace from the front of the data, it become the proper currency type. While it is a fix, it just won't do. Any ideas? </style></style>
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
Hi I am tryin to export a datatable to excel I am using the Following Code
public void createExcel(DataTable dtReportValues) {
string tableContents = ""; string style = "<style>.text { mso-number-format:Short Date;}</style>"; int value = RandomNumber(1, 99999); string fileName = "Report"+"_"+DateTime.Now.ToShortDateString()+"_"+value; fileName=fileName.Replace("/", "-"); Response.ContentType = "application/vnd.msexcel"; Response.AddHeader("Content-Disposition", "attachment;filename="+fileName+".xls"); Response.Charset = "";
string values = "";
values = "<tr> " + "<td align=\"center\"><b>Inquiry ID</b></td> " + "<td align=\"center\"><b>Website</b></td> " + "<td align=\"center\"><b>Date of Inquiry</b></td>" + "<td align=\"center\"><b>Customer name</b></td>" + "<td align=\"center\"><b>Company Name</b></td>" + "<td align=\"center\"><b>Lead Source</b></td>" + "<td align=\"center\"><b>Stats ID</b></td>" + "<td align=\"center\"><b>Service</b></td>" + "<td align=\"center\"><b>Sales Executive</b></td>" + "<td align=\"center\"><b>Form name</b></td>" + "<td align=\"center\"><b>Stage</b></td>" + "<td align=\"center\"><b>Status</b></td>" + "</tr>";
for (int i = 0; i < dtReportValues.Rows.Count; i++) { values += "<tr>" + "<td align=\"center\">" + dtReportValues.Rows[i][0] + "</td> " + "<td align=\"center\">" + dtReportValues.Rows[i][1] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][2] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][3] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][4] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][5] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][6] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][7] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][8] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][9] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][10] + "</td>" + "<td align=\"center\">" + dtReportValues.Rows[i][11] + "</td>" + "</tr>"; }
string brs = "<tr><td></td></tr>"; for (int i = 0; i < 12; i++) { brs += "<tr><td></td></tr><tr><td></td></tr>"; }
tableContents += "<table>" + "<tr>" + "<td>" + "<table style=\"border:solid 1px;\">" + values + "</table >" + "</td>" + "</tr>" + "</table>";
Response.Write(style); Response.Write(tableContents); Response.End();
}
the problem here is,in the Date of inquiry field in some dates the 0's are getting ommitted..i want the data in the excel to be as it is in the datatable..i read about mso formats but have no clue as to how to implement it...a code sample would do a great deal..thanx
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Hi I got error at RendoerControl. Following Line. DataGrid1.RenderControl(oHtmlTextWriter)
Like - Datagrid1 mus be write inside Form contro and make is runat= server........
Thanks sanjuvrm@rediffmail.com
gdsgeyeyeye e eye ye ye ye y
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I've solved that just by overriding the "VerifyRenderingInServerForm" in the code behind:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control) ' empty, needed for export2Excel to work. End Sub
--- The only way to solve a problem is reboot...
modified on Friday, May 16, 2008 5:29 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |