Export pie chart to powerpoint using c# - asp.net

i am trying to Export a pie chart to powerpoint slide uisng c# but not found any similar article which can help me...
please provide me some example or provide some useful link which can help me in achieving this functionality easily...
thanks,
Aman

we are using hipdf library but this is paid and we are converting html to image first and then showing this image on ppt slide. You can also do it by using inkscape exe file

In button_click event write following code.
GridView1.AllowPaging = false; //write this code only if paging is enabled.
GridView1.DataBind(); //write this code only if paging is enabled.
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.ppt");//for text file write FileName.txt
Response.Charset = "";
// If you want the option to open the Excel file without saving than comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ppt";\\for text file write vnd.txt
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
GridView1.AllowPaging = true; //write this code only if paging is enabled.
GridView1.DataBind();//write this code only if paging is enabled.
You will have to override function of VerifyRenderingInServerForm like this
public override void VerifyRenderingInServerForm(Control control)
{
//Keep it empty
}
And to avoid exception you have to set property of
<%# Page Language="C#" EnableEventValidation="false" %>

Related

export data to gridview from excel

Response.ClearContent();
Response.AppendHeader("content.disposition", "attachment;filename=check.xls");
Response.ContentType = "application/ms-excel";
StringWriter strwriter = new StringWriter();
HtmlTextWriter htmlwriter = new HtmlTextWriter(strwriter);
GridView2.RenderControl(htmlwriter);
Response.Write(strwriter.ToString());
Response.End();
I 'm trying to import data to excel all the code is executing well but nothing is happing no file is generating, please help me I'm stuck.
It should work if you change content.disposition for content-disposition:
Response.AppendHeader("content-disposition", "attachment;filename=check.xls");
Two additional settings are also required:
1) Event validation must be deactivated at the page level:
<%# Page EnableEventValidation="false" ... %>
2) The following page function must be overridden (it can stay empty):
public override void VerifyRenderingInServerForm(Control control)
{
}

Export Excel from grid not working on Ajax Model PopUp

Hi i am trying to export grid data to excel but it is not working in IE8.I am using a Ajax Modal PopUp dialog box containing 2 buttons 'ok' and 'close'.On Ok click i want to download excel file.it works fine in Mozilla but in IE its not working.I am using below code. please suggest me how to do that?Also when i open file first it show warning before opening file how to handle that?
Response.Clear();
Response.Buffer = true;
string filename = "Checkout";
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".adt");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<head>");
Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
Response.Write("<!--[if gte mso 9]><xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
Response.Write("<x:Name>Sheet1</x:Name>");
Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Print>");
Response.Write("<x:ValidPrinterInfo/>");
Response.Write("</x:Print>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]--> ");
Response.Write("</head>");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView gv = new GridView();
gv.AutoGenerateColumns = true;
gv.DataSource = dt;
gv.DataBind();
gv.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
You get warning because tehnically speaking this is not export to excel, but you send a html with a wrong headers to trick browser to open this content with excel.
Better use native Excel library and generate real Excel file on the server, for example EPPlus, it's open source and doesn't require excel on server.
Here is the example of ashx handler that generates excel file from DataTable
https://stackoverflow.com/a/9569827/351383

Exporting gridview to microsoft powerpoint in c#

I want to export gridview to powerpoint.I have the following code.But I have the following problems:
when I am using it for ms office 2010.its giving error:
Powerpoint cannot read c:\users\filename.ppt. The presentation cannot
be opened. Your antivirus program may prevent you from opening the
presentation. To fix this problem, make sure your antivirus program is
current and working correctly. If the problem persists and the
presentation is from someone that you trust, turn off your antivirus
program, and then try to open the presentation again. If you do this,
make sure you turn on your antivirus program again after you open the
presentation.
when I am using it for ms office 2007,its opening but there is no gridview
CODE:
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=FileName.ppt");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Charset = "";
// this.Response.ContentType = "application/vnd.openxmlformats- officedocument.presentationml.presentation";
this.Response.ContentType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
this.Response.ContentType = "application/vnd.ms-powerpoint";
//Response.ContentType = "application/vnd.ppt";
GridView2.AllowPaging = false;
GridView2.DataBind();
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
Response.Flush();
Try to use an external library to generate your ppt or pptx.
Like aspose.net or Open xml.

Export a data set to Excel and raise a file download dialog from an asp.net web method

I am using the following code to export a data set to an Excel sheet.
[WebMethod]
public static void ExporttoExcel()
{
DataSet ds;
productfactory pf=new productfactory();
ds = pf.getproducts();
HttpResponse response = HttpContext.Current.Response;
// first let's clean up the response.object
response.Clear();
response.Charset = "";
response.ContentEncoding = System.Text.Encoding.Default;
// set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"products.xls\"");
// create a string writer
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// instantiate a datagrid
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
string filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\products.xls";
response.Write(sw.ToString());
// response.End();
}
}
}
The problem is that it's not raising file download and hence no export is taking place. The same code works fine in a normal method. But with the web method it's not working.
I suggest to make an HttpHandler ending in ashx, and place inside him your code that create the excel file.
then call it from your javascript code like that.
document.location.href = "ExporttoExcel.ashx";
The problem is that WebMethods are not designed to allow you to interact with the Response object (evident in that it wasn't available and you had to use HttpContext.Current.Response to get to it). WebMethods are designed to be blackbox to the user. They will perform and action and/or return a value.
Perhaps you can give us a better idea of what you are trying to accomplish and we can suggest an alternate solution.
u can use to create a dynamic iframe with URL set to the Web Handler to generate the Excel this will raise the file download with out posting the current page.

exporting sql query result to excel

In my asp.net application i wanted to export the SQL query result to Excel and that excel should be avaliable to the user as a download.
Please help
I find working with excel to be a real headache, but it's possible to do just about anything if you want to. What features do you need to leverage, because offering a csv file instead is much easier!
Do you have SSRS, you could offer the query as an SSRS report and it is automatically available as an excel download!
If your on MS SQL Server, reporting services are available for free and can do this for you easily, you can also export to PDF and Word.
If not, or if its just a one off try here
you can show your result in a datagrid. after that you can export this grid to excel file.
do like this :
I pass grid by session.
Control grdList;
GridView grdList1 = Session["GridView"] as GridView;
if (grdList1 == null)
{
grdList = (DataGrid)Session["GridView"];
}
else
{
grdList = (GridView)Session["GridView"];
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ExportList.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
Response.ContentEncoding = System.Text.Encoding.UTF8;// GetEncoding(1256);// UTF8;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
grdList.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

Resources