将HighChart导出为excel文件中的图像以及其他页面内容


Export HighChart as an image in excel file together with the other page contents

将HighChart与其他页面内容(如表格、文本等)一起导出为excel文件中的图像。当我单击导出按钮时,整个页面内容将通过页眉保存为excel文件,但不将所有页面内容导出到excel文件,而是排除了HighChart Graph。我认为解决方案是将图形导出为excel中的图像,但我不知道如何做到这一点。有人知道怎么做吗,或者知道如何解决这个问题吗?

  1. 这是高图文档上的链接。这将帮助您导出图像并存储它。

  2. a) 文档#1
    b) 文档#2
    这将有助于你使用PHPExcel类API。

  3. 最后使用PHPExcel类将图像粘贴到一张纸上:一张或两张;

还有问题吗?看到链接:一,二
PHPExcel的官方例子:在这里。

祝你好运!

首先必须通过ajax将svgtext和csv文本发送到服务器。然后执行以下操作:

public JsonResult ExportToImage(字符串base64,字符串graphdata){尝试{

            var base64String = base64.Remove(0, 1);
            var rows = graphdata.Split(''n');
        byte[] bytes = Convert.FromBase64String(base64);
        var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "Content''Images''");
            DirectoryInfo di = new DirectoryInfo(path);
            FileInfo[] files = di.GetFiles("*.xls")
                                 .Where(p => p.Extension == ".xls").ToArray();
            foreach (FileInfo file in files)
                try
                {
                    file.Attributes = FileAttributes.Normal;
                    System.IO.File.Delete(file.FullName);
                }
                catch { }
            using (Image image = Image.FromStream(new MemoryStream(bytes)))
        {
            image.Save(path+"output.png", ImageFormat.Jpeg);  // Or Png
        }
            var xlApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlApp.Workbooks.Add();
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = xlWorkBook.Sheets[1];
            for(var y=0; y<rows.Count();y++)
            {
                var row = rows[y];
                var columValues = row.Split(',');
                for (var x = 0; x < columValues.Count(); x++)
                {
                    xlWorkSheet.Cells[y+20, x+1] = columValues[x];
                }
            }

            xlWorkSheet.Shapes.AddPicture(path + "output.png", MsoTriState.msoFalse, MsoTriState.msoCTrue, 0, 0, -1, -1);
            var fileName = string.Format("GraphDataExport{0}.xls", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"));
            xlWorkBook.SaveAs(path + fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal);
            xlWorkBook.Close(true);
            xlApp.Quit();
            Marshal.ReleaseComObject(xlApp);
            return Json(fileName);
        }
        catch (Exception e)
        {
            return Json(e.Message + Environment.NewLine + e.InnerException + Environment.NewLine + e.Data + Environment.NewLine);
        }
    }

现在您可以对文件执行window.location操作