不完全相同的問題,但我們遇到各種麻煩試圖保持Spreadsheet齒輪圖圖像在我們的MVC應用程序的上下文中,並決定採用一種方法,其中圖表作爲png圖像保存到服務器上,然後從服務器回到視圖。
這是代碼保存在服務器上的Excel圖表和在剃刀視圖檢索它:
<!-- language: lang-cs -->
// Get the image from the spreadsheet
SpreadsheetGear.Shapes.IShape chart7 = worksheet.Shapes["Chart 7"];
SpreadsheetGear.Drawing.Image image7 = new SpreadsheetGear.Drawing.Image(chart7);
saveChartImage(image7, "Chart7.png");
//Save chart images to the server
private void saveChartImage(SpreadsheetGear.Drawing.Image image, string chartName)
{
var imageFile = System.IO.Path.Combine(imagePath, chartName);
System.Drawing.Image bitmap = image.GetBitmap();
bitmap.Save(imageFile, System.Drawing.Imaging.ImageFormat.Png);
}
// Action result to get image
public ActionResult getImage(string imageDir, string filename)
{
var file = filename;
var fullPath = Path.Combine(imageDir, file);
return File(fullPath, "image/png", file);
}
檢索在視圖中的圖像:
<img src="@Url.Action("getImage", new { imageDir = "~/images/" "filename = "Chart7.png" })" />
我們已經用這種方法在一些非常龐大和複雜的電子表格(6 - 8MB)上。該代碼調用了來自16個散點圖的400多個數據點的圖像。這些圖表在服務器上大約爲16KB,並且據我所知,保存/檢索時間受Internet連接而不是服務器的限制。
這種方法的缺點是它不適合多用戶環境。要做到這一點,您需要創建用戶會話並給出用戶唯一的圖表名稱。
我真的不明白這與我的問題有什麼關係?你所展示的代碼已經是我所擁有的代碼了,它是「問題」,問題不在於產生的圖像,而是由於它使得它,電子表格設計爲每個點分配了大量內存並將其分割成很多,而且當你的圖表每個有96000點,並且每個文件有100個圖表時,所有的地圖都會打破。問題是,我似乎無法通過檢查圖表有多少點(points.count)來解決這個問題,因爲它已經分配了點數! –
需要說明的是,我們並不是在談論相同的數據大小,我的文件高達300MB,我有100 000個文件,每個文件最多包含300個左右的圖表,每個圖表每個「96000點」圖表「(vs 400爲你),所以你沒有達到這些限制是非常正常的。 –