 |
|
 |
I'm trying to run this, it's saying:
Error 1 Could not load type 'Glasses.Test.DataGridExport'.
What am I missing? Any help would really help, thanks.
|
|
|
|
 |
|
 |
The following site demonstrates how to export a DataTable, DataSet or List<> into a "proper" Excel 2007 .xlsx file (rather than exporting a .csv file, and getting Excel to open it).
It uses the OpenXML libraries, so you don't need to have Excel installed on your server.
http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm[^]
Best of all, all of the source is provided, free of charge, along with a demo of how to use it.
|
|
|
|
 |
|
 |
The article was written in 2005 and is compatible with older versions of Excel and Word.
|
|
|
|
 |
|
 |
Hi,
Thanks for the article,
I am facing one issue, i am populating data from dataset to gridview, which will be rendered to export.
when i have more than 50000 records i am only able to see 22579 records,
Is it there any limit on export?
would you please help me
Thanks in advance
|
|
|
|
 |
|
 |
exporting gridview along with some text at the top of the sheet
I want to export a gridview to excel but need to have company name and some other details at the top of the excel sheet
help me to get that
thanks in advance
|
|
|
|
 |
|
 |
I'm using this technique and it works fine for the PC. However, for a Mac the word document margins are too wide for the page, even if you change to landscape and narrow margins.
Here's the code:
For PC download:
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/msword"
Response.ContentEncoding = System.Text.Encoding.UTF7
Dim strFileName = "U" + Me.UnitId + "_" + Now.Date.ToShortDateString + ".doc"
Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileName)
Response.Charset = ""
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.tblPrint.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.End()
Response.Flush()
For Mac download:
Response.Buffer = True
Response.ContentType = "application/msword"
Dim strFileName = "U" + Me.UnitId + "_" + Now.Date.ToShortDateString + ".doc"
Response.AppendHeader("Content-Disposition", "attachment;filename=" + strFileName)
Response.Charset = ""
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.divPrint.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
Response.End()
Response.Flush()
This code was written by a programmer who no longer works with us. It looks to me to be identical except for the character encoding for PC download. Any assistance would be greatly appreciated.
|
|
|
|
 |
|
 |
I am using the following code to export the data from grid to text, but it contains html tag also,
can u pls help me to export in plain text(With out any tag )
Response.AddHeader("content-disposition", "attachment;filename=sample.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
this.ClearControls(dgrid);
dgrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
Thanks in advance
|
|
|
|
 |
|
 |
can we divide cells further.
like there are 3 columns and
delhi gujrat goa
and then two information has to be shown in delhi and division of delhi cell in next row.
delhi
agency1agency 2
plz provid eme with the code..otherwise gv me sum alternative
|
|
|
|
 |
|
 |
I need to export datagrid to excel using VB.NET. Please help me.
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
Hi,
with this Excel .NET component you can easily export DataGrid to Excel.
Here is an Excel VB.NET sample how to accomplish this from your Excel ASP.NET project:
Dim dataTable = DirectCast(dataGrid.DataSource, DataTable)
Dim ef = New ExcelFile()
Dim ws = ef.Worksheets.Add(dataTable.TableName)
ws.InsertDataTable(dataTable, "A1", True)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls")
ef.SaveXls(Response.OutputStream)
Response.[End]()
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
i need to export three datagrid's content and some other content in to single excel sheet.May i know how to do this?
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
Hi,
you are right! If you want to produce Excel binary files from your Excel ASP.NET applications, I recommend you take a look at this Excel .NET component.
Here is a sample Excel C# code how to export DataGrid to Excel:
var dataTable = (DataTable)dataGrid.DataSource;
var ef = new ExcelFile();
var ws = ef.Worksheets.Add(dataTable.TableName);
ws.InsertDataTable(dataTable, "A1", true);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls");
ef.SaveXls(Response.OutputStream);
Response.End();
|
|
|
|
 |
|
 |
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();
}
|
|
|
|
 |
|
 |
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();
}
|
|
|
|
 |