 |
|
 |
Thanks my dear friend....
|
|
|
|
 |
|
 |
Hi,
I am also facing the same problem. Any one in the forum know the solution for the same? Appriciate your help.
Regards
Praveen Paleti
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
For exporting DataTable to Word you should use C# mail merge functionality.
Here is a sample C# code how to mail merge DataTable to Word document with this C# / VB.NET Word component and ASP.NET export to Word so user can download a Word document in real DOCX format - not HTML with different extension:
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
var dataTable = new DataTable("People")
{
Columns =
{
new DataColumn("Name", typeof(string)),
new DataColumn("Surname", typeof(string))
},
Rows =
{
new object[] { "John", "Doe" },
new object[] { "Fred", "Nurk" },
new object[] { "Hans", "Meier" },
new object[] { "Ivan", "Horvat" }
}
};
var document = new DocumentModel();
document.Sections.Add(
new Section(document,
new Table(document,
new TableRow(document,
new TableCell(document,
new Paragraph(document, "Name")),
new TableCell(document,
new Paragraph(document, "Surname"))),
new TableRow(document,
new TableCell(document,
new Paragraph(document,
new Field(document, FieldType.MergeField, "RangeStart:People"),
new Field(document, FieldType.MergeField, "Name"))),
new TableCell(document,
new Paragraph(document,
new Field(document, FieldType.MergeField, "Surname"),
new Field(document, FieldType.MergeField, "RangeEnd:People")))))));
document.MailMerge.ExecuteRange(dataTable);
using (MemoryStream documentStream = new MemoryStream())
{
document.Save(documentStream, SaveOptions.DocxDefault);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=Document.docx");
documentStream.WriteTo(Response.OutputStream);
Response.End();
}
|
|
|
|
 |
|
 |
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!
|
|
|
|
 |
|
|
 |
|
 |
One question Where the Response.XXXXXXXX is coming from?
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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;
}
|
|
|
|
 |
|
 |
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>
|
|
|
|
 |
|
 |
How to Export data from grid having custom paging
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
Hi All,
how to export gridview to excel with multiple sheets without excel object.
Shrikanth
|
|
|
|
 |
|
|
 |
|
 |
Hello!
I have a WebSite (asp.net,C#,SQL2000).
When I press F5 to debug my website.
error: "Unable to connect to VS localhost website"
(I checked "Integrated Windows Authentication" & "Anonymous Access" in property of site IIS from Directory Security --> Edit)
help me!!!
thanks a lot!!
|
|
|
|
 |
|
 |
hi i ran the code for Exporting datagrid to excel
when i'm clicking the button to export its saying this error message and went back to debug window..
"GridView1 items should be placed in form tag with runat=server"..etc
but my grid is ther in the form only, why i get this error!.. please tell me
i'm in need of exporting (its a module of my project)
yours,
vivek
|
|
|
|
 |
|
 |
guys could you help me ,where can i get a tutorial video for this kinnda stuff
|
|
|
|
 |
|
 |
Hi,
You can find many video tutorials on www.videos.gridviewguy.com. It comes with a small fee.
Thanks,
Azam
Mohammad Azam
azamsharp@gmail.com
www.gridviewguy.com
videos.gridviewguy.com
Houston, TEXAS
|
|
|
|
 |
|
 |
hi!
I need help!! i already creating datagrid and convert it into powerpoint slide by using the below coding:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'create connection object containing connection string
Dim Connection As New SqlConnection("server=(local);uid=sa;pwd=sa;database=pubs")
' create dataAdapter object containing query string
Dim Adapter As New SqlDataAdapter("Select * from authors", Connection)
'create new empty dataset object
Dim DS = New DataSet()
'fill dataset object with result of query
Adapter.Fill(DS, "authors")
'place data set into datagrid control for user to look at
DataGrid().DataSource = DS.Tables("authors").DefaultView
'tell Datagrid control to display its contents
DataGrid.DataBind()
'clean up database connection
Connection.Close()
End Sub
Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
Dim way As String
Response.ClearContent()
Response.AddHeader("content-disposition", "attachment;filename=Filename.ppt")
Response.ContentType = "application/powerpoint"
Dim sw As New System.IO.StringWriter()
Dim htw As New System.Web.UI.HtmlTextWriter(sw)
DataGrid.RenderControl(htw)
Response.Write(way)
Response.Write(sw.ToString())
Response.End()
End Sub
My problem is how am i going to use the data in the datagrid which i build and apply in another slides(given by my supervisor)?
thank you
|
|
|
|
 |
|
 |
Hi Azam,
I am using ur Code for Exporting Data from Grid to Excel.if I put Paging then i get following Error.
Control 'DataGrid2__ctl3__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.
My Code is like this
*****************************************************************************
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);
dgInwardViewer.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
*************************************************************************
Thank you,
|
|
|
|
 |
|
 |
When you open this file, then try to do a SaveAs, it tried to Save as a web page. How do you get it to default to Excel?
Elizabeth Gee
Information Architect - .Net Developer
http://www.nwtd.com
|
|
|
|
 |
|
 |
This works perfectly, thanks!
I only have one question - I want to open the excel-document from a pop-up that closes itself upon the opening of the excel-document. Is such a thing even possible?
Because Response is used to generate the excel-document, all solutions I've tried *either* closes the pop-up, *or* never generates the excel-document. The only workaround I've found is to use a timer on the pop-up and then call self.close(). Unfortunately this is not a practical solution, as I cannot be sure how long it will take the excel-document to generate, and therefore may end up closing it much too soon, or leaving it open for way too long.
Do you know of another way I might solve this problem? I'm afraid the timer is the only way to do it, but would love to learn of another solution.
Thank you!
Maria
|
|
|
|
 |