提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|其它|编辑:郝浩|2011-09-15 12:01:13.000|阅读 1178 次
概述:图表支持是Aspose.Slides for .NET 用户所询问得非常普遍的问题。使用Aspose组件中的Aspose.Cells for .NET,可以创建 MS Excel格式的图表,然后再使用Aspose.Slides for .NET将图表嵌入成OLE对象。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
图表支持是Aspose.Slides for .NET用户所询问得非常普遍的问题。使用Aspose组件中的Aspose.Cells for .NET,可以创建 MS Excel格式的图表,然后再使用Aspose.Slides for .NET将图表嵌入成OLE对象。具体实现步骤如下:
1、使用Aspose.Cells创建一个Excel图表
2、使用Aspose.Cells设置图表的OLE大小
3、利用Aspose.Cells获取图表图像
4、利用Aspose.Slides将图表作为OLE对象嵌入到.ppt演示文档中
5、替换第3步中获得的图像
6、将输出的演示写入到磁盘
[C#]
public static void Run()
{
//Step - 1: Create an excel chart using Aspose.Cells
//--------------------------------------------------
//Create a workbook
Workbook wb = new Workbook();
//Add an excel chart
int chartRows = 55;
int chartCols = 25;
int chartSheetIndex = AddExcelChartInWorkbook(wb, chartRows, chartCols);
//Step - 2: Set the OLE size of the chart. using Aspose.Cells
//-----------------------------------------------------------
wb.Worksheets.SetOleSize(0, chartRows, 0, chartCols);
//Step - 3: Get the image of the chart with Aspose.Cells
//-----------------------------------------------------------
Bitmap imgChart = wb.Worksheets[chartSheetIndex].Charts[0].ToImage();
//Save the workbook to stream
MemoryStream wbStream = wb.SaveToStream();
//Step - 4 AND 5
//-----------------------------------------------------------
//Step - 4: Embed the chart as an OLE object inside .ppt presentation using Aspose.Slides
//-----------------------------------------------------------
//Step - 5: Replace the object changed image with the image obtained in step 3 to cater Object Changed Issue
//-----------------------------------------------------------
//Create a presentation
Presentation pres = new Presentation();
Slide sld = pres.GetSlideByPosition(1);
//Add the workbook on slide
AddExcelChartInPresentation(pres, sld, wbStream, imgChart);
//Step - 6: Write the output presentation on disk
//-----------------------------------------------------------
pres.Write("c:\\output.ppt");
}
static int AddExcelChartInWorkbook(Workbook wb, int chartRows, int chartCols)
{
//Array of cell names
string[] cellsName = new string[]
{
"A1", "A2", "A3", "A4",
"B1", "B2", "B3", "B4",
"C1", "C2", "C3", "C4",
"D1", "D2", "D3", "D4",
"E1", "E2", "E3", "E4"
};
//Array of cell data
int[] cellsValue = new int[]
{
67,86,68,91,
44,64,89,48,
46,97,78,60,
43,29,69,26,
24,40,38,25
};
//Add a new worksheet to populate cells with data
int dataSheetIdx = wb.Worksheets.Add();
Worksheet dataSheet = wb.Worksheets[dataSheetIdx];
string sheetName = "DataSheet";
dataSheet.Name = sheetName;
//Populate DataSheet with data
for (int i = 0; i < cellsName.Length; i++)
{
string cellName = cellsName[i];
int cellValue = cellsValue[i];
dataSheet.Cells[cellName].PutValue(cellValue);
}
//Add a chart sheet
int chartSheetIdx = wb.Worksheets.Add(SheetType.Chart);
Worksheet chartSheet = wb.Worksheets[chartSheetIdx];
chartSheet.Name = "ChartSheet";
//Add a chart in ChartSheet with data series from DataSheet
int chartIdx = chartSheet.Charts.Add(ChartType.Column, 0, chartRows, 0, chartCols);
Chart chart = chartSheet.Charts[chartIdx];
chart.NSeries.Add(sheetName + "!A1:E1", false);
chart.NSeries.Add(sheetName + "!A2:E2", false);
chart.NSeries.Add(sheetName + "!A3:E3", false);
chart.NSeries.Add(sheetName + "!A4:E4", false);
//Set ChartSheet an active sheet
wb.Worksheets.ActiveSheetIndex = chartSheetIdx;
return chartSheetIdx;
}
static void AddExcelChartInPresentation(Presentation pres, Slide sld, Stream wbStream, Bitmap imgChart)
{
Aspose.Slides.Picture pic = new Aspose.Slides.Picture(pres, imgChart);
int picId = pres.Pictures.Add(pic);
int slideWidth = pres.SlideSize.Width;
int slideHeight = pres.SlideSize.Height;
int x = 0;
byte[] chartOleData = new byte[wbStream.Length];
wbStream.Position = 0;
wbStream.Read(chartOleData, 0, chartOleData.Length);
OleObjectFrame oof = sld.Shapes.AddOleObjectFrame(x, 0, slideWidth, slideHeight,
"Excel.Sheet.8", chartOleData);
oof.PictureId = picId;
}
[Visual Basic]
Shared Sub Run()
'Step - 1: Create an excel chart using Aspose.Cells
'--------------------------------------------------
'Create a workbook
Dim wb As Workbook = New Workbook()
'Add an excel chart
Dim chartRows As Integer = 55
Dim chartCols As Integer = 25
Dim chartSheetIndex As Integer = AddExcelChartInWorkbook(wb, chartRows, chartCols)
'Step - 2: Set the OLE size of the chart. using Aspose.Cells
'-----------------------------------------------------------
wb.Worksheets.SetOleSize(0, chartRows, 0, chartCols)
'Step - 3: Get the image of the chart with Aspose.Cells
'-----------------------------------------------------------
Dim imgChart As Bitmap = wb.Worksheets(chartSheetIndex).Charts(0).ToImage()
'Save the workbook to stream
Dim wbStream As MemoryStream = wb.SaveToStream()
'Step - 4 AND 5
'-----------------------------------------------------------
'Step - 4: Embed the chart as an OLE object inside .ppt presentation using Aspose.Slides
'-----------------------------------------------------------
'Step - 5: Replace the object changed image with the image obtained in step 3 to cater Object Changed Issue
'-----------------------------------------------------------
'Create a presentation
Dim pres As Presentation = New Presentation()
Dim sld As Slide = pres.GetSlideByPosition(1)
'Add the workbook on slide
AddExcelChartInPresentation(pres, sld, wbStream, imgChart)
'Step - 6: Write the output presentation on disk
'-----------------------------------------------------------
pres.Write("c:\test\output2.ppt")
End Sub
Shared Function AddExcelChartInWorkbook(ByVal wb As Workbook, ByVal chartRows As Integer, ByVal chartCols As Integer) As Integer
Dim cellsName As String() = { _
"A1", "A2", "A3", "A4", _
"B1", "B2", "B3", "B4", _
"C1", "C2", "C3", "C4", _
"D1", "D2", "D3", "D4", _
"E1", "E2", "E3", "E4" _
}
'Array of cell data
Dim cellsValue As Integer() = { _
67, 86, 68, 91, _
44, 64, 89, 48, _
46, 97, 78, 60, _
43, 29, 69, 26, _
24, 40, 38, 25 _
}
'Add a new worksheet to populate cells with data
Dim dataSheetIdx As Integer = wb.Worksheets.Add()
Dim dataSheet As Worksheet = wb.Worksheets(dataSheetIdx)
Dim sheetName As String = "DataSheet"
dataSheet.Name = sheetName
'Populate DataSheet with data
For i As Integer = 0 To cellsName.Length - 1
Dim cellName As String = cellsName(i)
Dim cellValue As Integer = cellsValue(i)
dataSheet.Cells(cellName).PutValue(cellValue)
Next
'Add a chart sheet
Dim chartSheetIdx As Integer = wb.Worksheets.Add(SheetType.Chart)
Dim chartSheet As Worksheet = wb.Worksheets(chartSheetIdx)
chartSheet.Name = "ChartSheet"
'Add a chart in ChartSheet with data series from DataSheet
Dim chartIdx As Integer = chartSheet.Charts.Add(ChartType.Column, 0, chartRows, 0,
chartCols)
Dim _chart As Chart = chartSheet.Charts(chartIdx)
_chart.NSeries.Add(sheetName + "!A1:E1", False)
_chart.NSeries.Add(sheetName + "!A2:E2", False)
_chart.NSeries.Add(sheetName + "!A3:E3", False)
_chart.NSeries.Add(sheetName + "!A4:E4", False)
'Set ChartSheet an active sheet
wb.Worksheets.ActiveSheetIndex = chartSheetIdx
AddExcelChartInWorkbook = chartSheetIdx
End Function
Shared Sub AddExcelChartInPresentation(ByVal pres As Presentation, ByVal sld As Slide, ByVal wbStream As Stream, ByVal imgChart As Bitmap)
Dim pic As Aspose.Slides.Picture = New Aspose.Slides.Picture(pres, imgChart)
Dim picId As Integer = pres.Pictures.Add(pic)
Dim slideWidth As Integer = pres.SlideSize.Width
Dim slideHeight As Integer = pres.SlideSize.Height
Dim x As Integer = 0
Dim chartOleData(0 To wbStream.Length) As Byte
wbStream.Position = 0
wbStream.Read(chartOleData, 0, chartOleData.Length)
Dim oof As OleObjectFrame = sld.Shapes.AddOleObjectFrame
(x, 0, slideWidth, slideHeight,
"Excel.Sheet.8", chartOleData)
oof.PictureId = picId
End Sub
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn
文章转载自:慧都控件网面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
专业的电子表格控件,无需MS Excel也可满足一切Excel表格功能。
Aspose.SlidesAspose.Slides是第一个能在用户的应用程序中对PowerPoint文档进行管理的组件。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@pclwef.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢