将ASP Chart控件导出到Word文档

时间:2016-04-04 12:50:29

标签: asp.net c#-4.0

如何使用asp.net将asp图表控件导出到word文档?

enter image description here

我必须将此图表导出到Word。

1 个答案:

答案 0 :(得分:2)

最后我得到了解决方案。

首先我将图表保存为Png图像。

         Chart1.SaveImage(@"D:\Test\Sample1.png", ChartImageFormat.Png);

然后将PNG图像导出为单词。

        Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(); //If you're creating a document
        oWord.Visible = true;
        Object oMissing = System.Reflection.Missing.Value;
        var oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
        oPara1.Range.Text = "Chart Sample";
        oPara1.Range.InsertParagraphAfter();
        System.Drawing.Image Picture = myimage;*// Assigned saved png image*
        var oPara2 = oDoc.Content.Paragraphs.Add(ref oMissing);
        Thread thread = new Thread(() => Clipboard.SetImage(Picture));
        thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
        thread.Start();
        thread.Join();

        oPara2.Range.Paste();
        oPara2.Range.InsertParagraphAfter();
        oDoc.SaveAs(docFilePath);
        oDoc.Close();
        oWord.Quit();