| |
 |
Convert Worksheet to Image with multiple Print Areas - Aspose.Cells
|
 |
This online demo demonstrates the ability of Aspose.Cells
for .NET to convert a worksheet to image file having multiple print areas.
The demo converts the worksheet having multiple print areas defined in to an image file. 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
|
<%@ Page Language="VB" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" Inherits="Aspose.Cells.Demos.VisualBasic.Sheet2ImageWithPrintArea"
Title="Convert Worksheet to Image with multiple Print Areas - Aspose.Cells Demos" Codebehind="convert-worksheet-to-image-with-multiple-printarea.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 with multiple Print Areas - 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/file-format-components/aspose.cells-for-.net-and-java/default.aspx"
style="color: blue; text-decoration: underline; text-underline: single">Aspose.Cells</a>
for .NET to convert a worksheet to image file having multiple print areas.</font></p>
<p class="componentdescriptiontxt">
<font face="Arial" size="2">The demo converts the worksheet having multiple print areas defined in to an image file. 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
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.Rendering
Partial Public Class Sheet2ImageWithPrintArea
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)
CreateStaticReport()
End Sub
Public Shared Sub CreateStaticReport()
'Instantiating an Workbook object
Dim workbook As New Workbook()
'Obtaining the reference of the newly added worksheet
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim cells As Cells = sheet.Cells
'Setting the value to the cells
Dim cell As Cell = cells("A1")
cell.PutValue("Employee")
cell = cells("B1")
cell.PutValue("Quarter")
cell = cells("C1")
cell.PutValue("Product")
cell = cells("D1")
cell.PutValue("Continent")
cell = cells("E1")
cell.PutValue("Country")
cell = cells("F1")
cell.PutValue("Sale")
cell = cells("A2")
cell.PutValue("David")
cell = cells("A3")
cell.PutValue("David")
cell = cells("A4")
cell.PutValue("David")
cell = cells("A5")
cell.PutValue("David")
cell = cells("A6")
cell.PutValue("James")
cell = cells("A7")
cell.PutValue("James")
cell = cells("A8")
cell.PutValue("James")
cell = cells("A9")
cell.PutValue("James")
cell = cells("A10")
cell.PutValue("James")
cell = cells("A11")
cell.PutValue("Miya")
cell = cells("A12")
cell.PutValue("Miya")
cell = cells("A13")
cell.PutValue("Miya")
cell = cells("A14")
cell.PutValue("Miya")
cell = cells("A15")
cell.PutValue("Miya")
cell = cells("A16")
cell.PutValue("Miya")
cell = cells("A17")
cell.PutValue("Miya")
cell = cells("A18")
cell.PutValue("Elvis")
cell = cells("A19")
cell.PutValue("Elvis")
cell = cells("A20")
cell.PutValue("Elvis")
cell = cells("A21")
cell.PutValue("Elvis")
cell = cells("A22")
cell.PutValue("Elvis")
cell = cells("A23")
cell.PutValue("Elvis")
cell = cells("A24")
cell.PutValue("Elvis")
cell = cells("A25")
cell.PutValue("Jean")
cell = cells("A26")
cell.PutValue("Jean")
cell = cells("A27")
cell.PutValue("Jean")
cell = cells("A28")
cell.PutValue("Ada")
cell = cells("A29")
cell.PutValue("Ada")
cell = cells("A30")
cell.PutValue("Ada")
cell = cells("B2")
cell.PutValue("1")
cell = cells("B3")
cell.PutValue("2")
cell = cells("B4")
cell.PutValue("3")
cell = cells("B5")
cell.PutValue("4")
cell = cells("B6")
cell.PutValue("1")
cell = cells("B7")
cell.PutValue("2")
cell = cells("B8")
cell.PutValue("3")
cell = cells("B9")
cell.PutValue("4")
cell = cells("B10")
cell.PutValue("4")
cell = cells("B11")
cell.PutValue("1")
cell = cells("B12")
cell.PutValue("1")
cell = cells("B13")
cell.PutValue("2")
cell = cells("B14")
cell.PutValue("2")
cell = cells("B15")
cell.PutValue("3")
cell = cells("B16")
cell.PutValue("4")
cell = cells("B17")
cell.PutValue("4")
cell = cells("B18")
cell.PutValue("1")
cell = cells("B19")
cell.PutValue("1")
cell = cells("B20")
cell.PutValue("2")
cell = cells("B21")
cell.PutValue("3")
cell = cells("B22")
cell.PutValue("3")
cell = cells("B23")
cell.PutValue("4")
cell = cells("B24")
cell.PutValue("4")
cell = cells("B25")
cell.PutValue("1")
cell = cells("B26")
cell.PutValue("2")
cell = cells("B27")
cell.PutValue("3")
cell = cells("B28")
cell.PutValue("1")
cell = cells("B29")
cell.PutValue("2")
cell = cells("B30")
cell.PutValue("3")
cell = cells("C2")
cell.PutValue("Maxilaku")
cell = cells("C3")
cell.PutValue("Maxilaku")
cell = cells("C4")
cell.PutValue("Chai")
cell = cells("C5")
cell.PutValue("Maxilaku")
cell = cells("C6")
cell.PutValue("Chang")
cell = cells("C7")
cell.PutValue("Chang")
cell = cells("C8")
cell.PutValue("Chang")
cell = cells("C9")
cell.PutValue("Chang")
cell = cells("C10")
cell.PutValue("Chang")
cell = cells("C11")
cell.PutValue("Geitost")
cell = cells("C12")
cell.PutValue("Chai")
cell = cells("C13")
cell.PutValue("Geitost")
cell = cells("C14")
cell.PutValue("Geitost")
cell = cells("C15")
cell.PutValue("Maxilaku")
cell = cells("C16")
cell.PutValue("Geitost")
cell = cells("C17")
cell.PutValue("Geitost")
cell = cells("C18")
cell.PutValue("Ikuru")
cell = cells("C19")
cell.PutValue("Ikuru")
cell = cells("C20")
cell.PutValue("Ikuru")
cell = cells("C21")
cell.PutValue("Ikuru")
cell = cells("C22")
cell.PutValue("Ipoh Coffee")
cell = cells("C23")
cell.PutValue("Ipoh Coffee")
cell = cells("C24")
cell.PutValue("Ipoh Coffee")
cell = cells("C25")
cell.PutValue("Chocolade")
cell = cells("C26")
cell.PutValue("Chocolade")
cell = cells("C27")
cell.PutValue("Chocolade")
cell = cells("C28")
cell.PutValue("Chocolade")
cell = cells("C29")
cell.PutValue("Chocolade")
cell = cells("C30")
cell.PutValue("Chocolade")
cell = cells("D2")
cell.PutValue("Asia")
cell = cells("D3")
cell.PutValue("Asia")
cell = cells("D4")
cell.PutValue("Asia")
cell = cells("D5")
cell.PutValue("Asia")
cell = cells("D6")
cell.PutValue("Europe")
cell = cells("D7")
cell.PutValue("Europe")
cell = cells("D8")
cell.PutValue("Europe")
cell = cells("D9")
cell.PutValue("Europe")
cell = cells("D10")
cell.PutValue("Europe")
cell = cells("D11")
cell.PutValue("America")
cell = cells("D12")
cell.PutValue("America")
cell = cells("D13")
cell.PutValue("America")
cell = cells("D14")
cell.PutValue("America")
cell = cells("D15")
cell.PutValue("America")
cell = cells("D16")
cell.PutValue("America")
cell = cells("D17")
cell.PutValue("America")
cell = cells("D18")
cell.PutValue("Europe")
cell = cells("D19")
cell.PutValue("Europe")
cell = cells("D20")
cell.PutValue("Europe")
cell = cells("D21")
cell.PutValue("Oceania")
cell = cells("D22")
cell.PutValue("Oceania")
cell = cells("D23")
cell.PutValue("Oceania")
cell = cells("D24")
cell.PutValue("Oceania")
cell = cells("D25")
cell.PutValue("Africa")
cell = cells("D26")
cell.PutValue("Africa")
cell = cells("D27")
cell.PutValue("Africa")
cell = cells("D28")
cell.PutValue("Africa")
cell = cells("D29")
cell.PutValue("Africa")
cell = cells("D30")
cell.PutValue("Africa")
cell = cells("E2")
cell.PutValue("China")
cell = cells("E3")
cell.PutValue("India")
cell = cells("E4")
cell.PutValue("Korea")
cell = cells("E5")
cell.PutValue("India")
cell = cells("E6")
cell.PutValue("France")
cell = cells("E7")
cell.PutValue("France")
cell = cells("E8")
cell.PutValue("Germany")
cell = cells("E9")
cell.PutValue("Italy")
cell = cells("E10")
cell.PutValue("France")
cell = cells("E11")
cell.PutValue("U.S.")
cell = cells("E12")
cell.PutValue("U.S.")
cell = cells("E13")
cell.PutValue("Brazil")
cell = cells("E14")
cell.PutValue("U.S.")
cell = cells("E15")
cell.PutValue("U.S.")
cell = cells("E16")
cell.PutValue("Canada")
cell = cells("E17")
cell.PutValue("U.S.")
cell = cells("E18")
cell.PutValue("Italy")
cell = cells("E19")
cell.PutValue("France")
cell = cells("E20")
cell.PutValue("Italy")
cell = cells("E21")
cell.PutValue("New Zealand")
cell = cells("E22")
cell.PutValue("Australia")
cell = cells("E23")
cell.PutValue("Australia")
cell = cells("E24")
cell.PutValue("New Zealand")
cell = cells("E25")
cell.PutValue("S.Africa")
cell = cells("E26")
cell.PutValue("S.Africa")
cell = cells("E27")
cell.PutValue("S.Africa")
cell = cells("E28")
cell.PutValue("Egypt")
cell = cells("E29")
cell.PutValue("Egypt")
cell = cells("E30")
cell.PutValue("Egypt")
cell = cells("F2")
cell.PutValue(2000)
cell = cells("F3")
cell.PutValue(500)
cell = cells("F4")
cell.PutValue(1200)
cell = cells("F5")
cell.PutValue(1500)
cell = cells("F6")
cell.PutValue(500)
cell = cells("F7")
cell.PutValue(1500)
cell = cells("F8")
cell.PutValue(800)
cell = cells("F9")
cell.PutValue(900)
cell = cells("F10")
cell.PutValue(500)
cell = cells("F11")
cell.PutValue(1600)
cell = cells("F12")
cell.PutValue(600)
cell = cells("F13")
cell.PutValue(2000)
cell = cells("F14")
cell.PutValue(500)
cell = cells("F15")
cell.PutValue(900)
cell = cells("F16")
cell.PutValue(700)
cell = cells("F17")
cell.PutValue(1400)
cell = cells("F18")
cell.PutValue(1350)
cell = cells("F19")
cell.PutValue(300)
cell = cells("F20")
cell.PutValue(500)
cell = cells("F21")
cell.PutValue(1000)
cell = cells("F22")
cell.PutValue(1500)
cell = cells("F23")
cell.PutValue(1500)
cell = cells("F24")
cell.PutValue(1600)
cell = cells("F25")
cell.PutValue(1000)
cell = cells("F26")
cell.PutValue(1200)
cell = cells("F27")
cell.PutValue(1300)
cell = cells("F28")
cell.PutValue(1500)
cell = cells("F29")
cell.PutValue(1400)
cell = cells("F30")
cell.PutValue(1000)
'Set Page Orientation
sheet.PageSetup.Orientation = PageOrientationType.Portrait
'Set Paper Size
sheet.PageSetup.PaperSize = PaperSizeType.PaperA4
'Show Headings
sheet.PageSetup.PrintHeadings = True
'Set Print Area
sheet.PageSetup.PrintArea = "A1:C30,D1:F30"
'Create a memory stream object.
Dim memorystream As New MemoryStream()
Dim imgOptions As New ImageOrPrintOptions()
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff
Dim sheetRender As New SheetRender(sheet, imgOptions)
'Convert worksheet to image.
sheetRender.ToTiff(memorystream)
memorystream.Seek(0, SeekOrigin.Begin)
'Set Response object to stream the image file.
Dim data() As Byte = memorystream.ToArray()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "image/tiff"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=SheetImage.tiff")
HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length)
'End response to avoid unneeded html after xls
HttpContext.Current.Response.End()
End Sub
End Class
|
|
|
|