Ich möchte eine Schaltfläche erstellen Option, die den gesamten Datenlistener nimmt und konvertiert es in eine PDF-Datei. Wie jemand dies in asp.net getan? Bitte kannst du ein Beispiel zeigen oder mich richtig leiten.Konvertieren/Exportieren von C# -Datenlisten-Steuerelement/(HTML-Seite) als eine PDF-Datei
Antwort
gefunden Nur ein Code-Snippet ein Mann ins Forum geschrieben, und obwohl ich mit anderen
Re teilen könnten: EXPORT Datagrid PDF in C#/Asp.Net
//*************************************************
//
// Author:
// Ryan Van Aken ([email protected])
// (C) 2009 Ryan Van Aken
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*************************************************
//SQL Connection Settings -----------
public string strConn = ConfigurationManager.ConnectionStrings["BLAH-Here"].ConnectionString;
//-----------------------------------
protected void Page_Load(object sender, EventArgs e)
{
//Grab the same data as the datagrid [report view] on the reporting page
//Then set the "ContentType" to "application/vnd.ms-excel" which will generate the .XSL file
//---Retrieve the Report from SQL, drop into DataSet, then Bind() it to a DataGrid
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlDataAdapter cmd1 = new SqlDataAdapter("EXEC [dbo].[spStatReport] @CompanyID=" + Session["CompanyID"] + ", @StatReportID=" + Request.QueryString["ReportID"].ToString() + ", @StartDate='" + Request.QueryString["StartDate"].Replace("-", "/").ToString() + "', @EndDate='" + Request.QueryString["EndDate"].Replace("-", "/").ToString() + "';", conn);
cmd1.SelectCommand.CommandType = CommandType.Text;
DataSet dsReports = new DataSet("tblReporting");
cmd1.Fill(dsReports);
conn.Close();
DataGrid dtaFinal = new DataGrid();
dtaFinal.DataSource = dsReports.Tables[0];
dtaFinal.DataBind();
dtaFinal.HeaderStyle.ForeColor = System.Drawing.Color.White;
dtaFinal.HeaderStyle.BackColor = System.Drawing.Color.DarkGray;
dtaFinal.ItemStyle.BackColor = System.Drawing.Color.White;
dtaFinal.AlternatingItemStyle.BackColor = System.Drawing.Color.AliceBlue;
//---Create the File---------
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
//---For PDF uncomment the following lines----------
//Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
//---For MS Excel uncomment the following lines----------
//Response.ContentType = "application/vnd.ms-excel";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
//---For MS Word uncomment the following lines----------
//Response.ContentType = "application/vnd.word";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
//---For CSV uncomment the following lines----------
//Response.ContentType = "text/csv";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.csv");
//---For TXT uncomment the following lines----------
//Response.ContentType = "text/plain";
//Response.AddHeader("content-disposition", "attachment;filename=FileName.txt");
EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//---Renders the DataGrid and then dumps it into the HtmlTextWriter Control
dtaFinal.RenderControl(hw);
//---Utilize the Response Object to write the StringWriter to the page
Response.Write(sw.ToString());
Response.Flush();
Response.Close();
Response.End();
}
Sie könnten this ausprobieren und den Inhaltstyp in PDF ändern.
Sie können Ihre Lösung nach PDFSharp eine sehr einfache PDF-Bibliothek für .net versuchen entwickeln
hey Dank Mann, das hat mir sehr geholfen :) God Speed – ferronrsmith
iTextSharp ist eine weitere Alternative zu betrachten. – RichardOD
Dies hat sehr gut akzeptiert es für mich nicht gesetzt Margen trotz allem, was ich setze sie auf der Website. Gibt es das überhaupt für den Word-Teil? Auch ich finde der PDF-Teil funktioniert nicht.
(Der große Export post)
- 1. C# eine Liste als Parameter-Funktion übergeben
- 2. C# - Laden Sie eine Textdatei als Klasse
- 3. C++: Eine abstrakte Klasse als Mitglied
- 4. zurückgeben mehr als eine Ausgabe auf C#
- 5. C++, eine Zeichenkette mit Leerzeichen als eine Einheit analysieren
- 6. eine Methode als eine Membervariable einer Klasse in C# Speichern
- 7. Etwas sowohl eine C-ID als auch eine Zeichenfolge machen?
- 8. Splitting eine Linie in C/C++ mit Leerzeichen als Trennzeichen
- 9. Vollständige C++ - Pipeline als Blackbox von R
- 10. C#: Verwendung von "self" als generischem Parameter?
- 11. C#: Erweitern von mehr als 1 Klasse
- 12. Verwenden von drand48_r als Zufallsgenerator in C
- 13. C++ unter Verwendung von ‚this‘ als Parameter
- 14. Kann eine Objective-c-Schnittstelle mehr als eine Implementierung haben?
- 15. Marshalling "als Zeichenfolge" -Parameter von C#
- 16. Führen Sie Powershell als Administrator von C#
- 17. Verwendung von Ostream als Referenz (C++)
- 18. C# enums als int
- 19. C++ * vs [] als Funktionsparameter
- 20. Neustart von nodejs als Prozess in C#
- 21. C++ - Speichern von Operator als char
- 22. Zugriff auf eine C++ - Funktion, die Zeiger als Eingabeargument von einem C#
- 23. Java schneller als C
- 24. C++ als Hochsprache?
- 25. Delegate von C# an c als Funktionsparameter übergeben
- 26. Zeiger als C++ Iterator
- 27. C# NaN als Doppel
- 28. Kann ich eine Liste <T> als eine Sammlung von Methodenzeigern verwenden? (C#)
- 29. C++: System Boost-Datei, die eine Liste von Dateien, die älter als eine bestimmte Zeit zurück
- 30. C - eine große Gruppe von Dateien, die als eine einzelne Ressource speichern
Nun, es funktionierte, ich bekam den PDF-Download, aber als ich versuchte, es zu öffnen, sagte Adobe Reader mir, dass die Datei beschädigt oder so etwas war. Die Datei konnte nicht gelesen werden. Es ist mehr Fortschritt als alles, was ich bis jetzt gesehen habe – Ortund