2010-01-09 22 views
1

J'ai besoin d'exporter quelques graphiques Microsoft (peut-être un ou plusieurs) vers un fichier PDF et Excel. Il doit se produire sur un clic de bouton et les graphiques doivent être directement exportés vers un PDF sans être rendus sur une page Web.Exporter des graphiques MS vers PDF et Excel

environnement utilisé: ASP.NET

S'il vous plaît suggérer l'approche pour y parvenir.

acclamations

Répondre

1

Voici un exemple de code pour l'exportation contrôle graphique MS Excel. J'espère que cela t'aides.

string tmpChartName = "test2.jpg"; 
    string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName; 

    Chart1.SaveImage(imgPath); 
    string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName); 

    Response.Clear(); 
    Response.ContentType = "application/vnd.ms-excel"; 
    Response.AddHeader("Content-Disposition", "attachment; filename=test.xls;"); 
    StringWriter stringWrite = new StringWriter(); 
    HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); 
    string headerTable = @"<Table><tr><td><img src='" + imgPath2 + @"' \></td></tr></Table>"; 
    Response.Write(headerTable); 
    Response.Write(stringWrite.ToString()); 
    Response.End();