| |
 |
Convert Worksheet to Image File - Aspose.Cells
|
 |
This online demo demonstrates the ability of Aspose.Cells
for .NET to convert a worksheet to image file.
The demo utilizes a template file which contains some formatted
data. It then converts the first worksheet in the workbook to image.
You can either open the output image file into your picture viewer
or save directly to your disk.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<%@ Page Language="VB" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" Inherits="Aspose.Cells.Demos.VisualBasic.Sheet2Image"
Title="Convert Worksheet to Image File - Aspose.Cells Demos" Codebehind="convert-worksheet-to-image-file.aspx.vb" %>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="Server">
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span> </p>
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_lft.jpg" width="19" /></td>
<td class="demos-heading-bg" width="100%">
<h2 class="demos-heading-bg">
<font face="Arial" size="4">Convert Worksheet to Image File - Aspose.Cells</font></h2>
</td>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_rt.jpg" width="19" /></td>
</tr>
</table>
</p>
<p class="componentdescriptiontxt">
<font face="Arial" size="2">This online demo demonstrates the ability of <a href="http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx"
style="color: blue; text-decoration: underline; text-underline: single">Aspose.Cells</a>
for .NET to convert a worksheet to image file.</font></p>
<p class="componentdescriptiontxt">
<font face="Arial" size="2">The demo utilizes a template file which contains some formatted
data. It then converts the first worksheet in the workbook to image.
You can either open the output image file into your picture viewer
or save directly to your disk.</font></p>
<p class="componentDescriptionTxt">
<asp:Button ID="btnExecute" runat="server" Text="Process" OnClick="btnExecute_Click"/> </p>
</asp:Content>
|
| Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
Imports System
Imports System.Data
Imports System.IO
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Aspose.Cells
Imports Aspose.Cells.Charts
Partial Public Class Chart2Image
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub btnExecute_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExecute.Click
CreateStaticReport()
End Sub
Protected Sub CreateStaticReport()
'Create a new Workbook.
Dim workbook As New Workbook()
'Get the first worksheet.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Set the name of worksheet
sheet.Name = "ChartSheet"
'Get the cells collection in the sheet.
Dim cells As Cells = workbook.Worksheets(0).Cells
'Put some values into different cells of the sheet.
cells("A1").PutValue("Region")
cells("A2").PutValue("France")
cells("A3").PutValue("Germany")
cells("A4").PutValue("England")
cells("A5").PutValue("Sweden")
cells("A6").PutValue("Italy")
cells("A7").PutValue("Spain")
cells("A8").PutValue("Portugal")
cells("B1").PutValue("Sale")
cells("B2").PutValue(70000)
cells("B3").PutValue(55000)
cells("B4").PutValue(30000)
cells("B5").PutValue(40000)
cells("B6").PutValue(35000)
cells("B7").PutValue(32000)
cells("B8").PutValue(10000)
'Create chart
Dim chartIndex As Integer = 0
chartIndex = sheet.Charts.Add(ChartType.Pie, 2, 4, 31, 15)
Dim chart As Chart = sheet.Charts(chartIndex)
'Set properties of chart title
chart.Title.Text = "Sales By Region"
chart.Title.TextFont.Color = System.Drawing.Color.Blue
chart.Title.TextFont.IsBold = True
chart.Title.TextFont.Size = 12
'Set properties of nseries
chart.NSeries.Add("B2:B8", True)
chart.NSeries.CategoryData = "A2:A8"
chart.NSeries.IsColorVaried = True
'Set the DataLabels in the chart
Dim datalabels As DataLabels
For i As Integer = 0 To chart.NSeries.Count - 1
datalabels = chart.NSeries(i).DataLabels
datalabels.Postion = LabelPositionType.Center
datalabels.IsCategoryNameShown = False
datalabels.IsValueShown = False
datalabels.IsPercentageShown = True
datalabels.IsLegendKeyShown = False
Next i
'Set the Legend.
Dim legend As Legend = chart.Legend
legend.Position = LegendPositionType.Left
'Create a memory stream object.
Dim ms As New MemoryStream()
'Conver the chart to image file.
chart.ToImage(ms, System.Drawing.Imaging.ImageFormat.Emf)
'Set Response object to stream the image file.
Dim data() As Byte = ms.ToArray()
Me.Context.Response.Clear()
Me.Context.Response.ContentType = "image/emf"
Me.Context.Response.AddHeader("content-disposition", "attachment; filename=ChartPic.emf")
Me.Context.Response.OutputStream.Write(data, 0, data.Length)
'End response to avoid unneeded html after xls
Me.Response.End()
End Sub
End Class
|
|
|
|