-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
571 lines (493 loc) · 27.9 KB
/
Form1.vb
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
Imports DevExpress.Export.Xl
Imports DevExpress.Spreadsheet
Imports System
Imports System.Diagnostics
Imports System.Drawing
Imports System.Globalization
Imports System.IO
Imports System.Windows.Forms
Namespace XLExportExample
Partial Public Class Form1
Inherits Form
Private invoice As Invoice
Private panelFont As XlFont
Private titleFont As XlFont
Private infoFont As XlFont
Private leftPanelBorder As XlBorder
Private leftPanelFormatting As XlCellFormatting
Private rightPanelFormatting As XlCellFormatting
Private headerRowFormatting As XlCellFormatting
Private evenRowFormatting As XlCellFormatting
Private oddRowFormatting As XlCellFormatting
Private infoFormatting As XlCellFormatting
Public Sub New()
InitializeComponent()
InitializeFormatting()
invoice = XLExportExample.Invoice.CreateSampleInvoice()
End Sub
Private Sub InitializeFormatting()
' Specify formatting settings for the even rows.
evenRowFormatting = New XlCellFormatting()
evenRowFormatting.Font = New XlFont()
evenRowFormatting.Font.Name = "Century Gothic"
evenRowFormatting.Font.SchemeStyle = XlFontSchemeStyles.None
evenRowFormatting.Fill = XlFill.SolidFill(Color.White)
' Specify formatting settings for the odd rows.
oddRowFormatting = New XlCellFormatting()
oddRowFormatting.CopyFrom(evenRowFormatting)
oddRowFormatting.Fill = XlFill.SolidFill(Color.FromArgb(242, 242, 242))
' Specify formatting settings for the header row.
headerRowFormatting = New XlCellFormatting()
headerRowFormatting.CopyFrom(evenRowFormatting)
headerRowFormatting.Font.Bold = True
headerRowFormatting.Font.Color = Color.White
headerRowFormatting.Fill = XlFill.SolidFill(Color.FromArgb(192, 0, 0))
' Set borders for the header row.
headerRowFormatting.Border = New XlBorder()
' Specify the top border and set its color to white.
headerRowFormatting.Border.TopColor = Color.White
' Specify the medium border line style.
headerRowFormatting.Border.TopLineStyle = XlBorderLineStyle.Medium
' Specify the bottom border for the header row.
' Set the bottom border color to dark gray.
headerRowFormatting.Border.BottomColor = Color.FromArgb(89, 89, 89)
' Specify the medium border line style.
headerRowFormatting.Border.BottomLineStyle = XlBorderLineStyle.Medium
' Specify formatting settings for the invoice header.
panelFont = New XlFont()
panelFont.Name = "Century Gothic"
panelFont.SchemeStyle = XlFontSchemeStyles.None
panelFont.Color = Color.White
' Set font attributes for the row displaying the invoice label and company name.
titleFont = panelFont.Clone()
titleFont.Size = 26
' Specify formatting settings for the worksheet range containing the name and contact details of the seller (the "Vader Enterprises" panel).
leftPanelFormatting = New XlCellFormatting()
' Set the cell background color to dark gray.
leftPanelFormatting.Fill = XlFill.SolidFill(Color.FromArgb(89, 89, 89))
leftPanelFormatting.Alignment = XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom)
leftPanelFormatting.NumberFormat = XlNumberFormat.General
' Set the right border for this range.
leftPanelBorder = New XlBorder()
' Set the right border color to white.
leftPanelBorder.RightColor = Color.White
' Specify the medium border line style.
leftPanelBorder.RightLineStyle = XlBorderLineStyle.Medium
' Specify formatting settings for the worksheet range containing general information about the invoice:
' its date, reference number and service description (the "Invoice" panel).
rightPanelFormatting = New XlCellFormatting()
' Set the cell background color to dark red.
rightPanelFormatting.Fill = XlFill.SolidFill(Color.FromArgb(192, 0, 0))
rightPanelFormatting.Alignment = XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom)
rightPanelFormatting.NumberFormat = XlNumberFormat.General
' Specify formatting settings and font attributes for the worksheet range containing buyer's contact information (the "Bill To" panel).
infoFormatting = New XlCellFormatting()
' Set the cell background color to light gray.
infoFormatting.Fill = XlFill.SolidFill(Color.FromArgb(217, 217, 217))
infoFormatting.Alignment = XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom)
infoFormatting.NumberFormat = XlNumberFormat.General
infoFont = panelFont.Clone()
infoFont.Color = Color.Black
End Sub
' Export the document to XLSX format.
Private Sub btnExportToXLSX_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExportToXLSX.Click
Dim fileName As String = GetSaveFileName("Excel Workbook files(*.xlsx)|*.xlsx", "Document.xlsx")
If String.IsNullOrEmpty(fileName) Then
Return
End If
If ExportToFile(fileName, XlDocumentFormat.Xlsx) Then
ShowFile(fileName)
End If
End Sub
' Export the document to XLS format.
Private Sub btnExportToXLS_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExportToXLS.Click
Dim fileName As String = GetSaveFileName("Excel 97-2003 Workbook files(*.xls)|*.xls", "Document.xls")
If String.IsNullOrEmpty(fileName) Then
Return
End If
If ExportToFile(fileName, XlDocumentFormat.Xls) Then
ShowFile(fileName)
End If
End Sub
Private Function GetSaveFileName(ByVal filter As String, ByVal defaulName As String) As String
saveFileDialog1.Filter = filter
saveFileDialog1.FileName = defaulName
If saveFileDialog1.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
Return Nothing
End If
Return saveFileDialog1.FileName
End Function
Private Sub ShowFile(ByVal fileName As String)
If Not File.Exists(fileName) Then
Return
End If
Dim dResult As DialogResult = MessageBox.Show(String.Format("Do you want to open the resulting file?", fileName), Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dResult = System.Windows.Forms.DialogResult.Yes Then
Process.Start(fileName)
End If
End Sub
Private Function ExportToFile(ByVal fileName As String, ByVal documentFormat As XlDocumentFormat) As Boolean
Try
Using stream As New FileStream(fileName, FileMode.Create)
' Create an exporter with the specified formula parser.
Dim exporter As IXlExporter = XlExport.CreateExporter(documentFormat, New XlFormulaParser())
' Create a new document and begin to write it to the specified stream.
Using document As IXlDocument = exporter.CreateDocument(stream)
' Generate the document content.
GenerateDocument(document)
End Using
End Using
Return True
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
Private Sub GenerateDocument(ByVal document As IXlDocument)
' Specify the document culture.
document.Options.Culture = CultureInfo.CurrentCulture
' Add a new worksheet to the document.
Using sheet As IXlSheet = document.CreateSheet()
' Specify the worksheet name.
sheet.Name = "Invoice"
' Specify page settings.
sheet.PageSetup = New XlPageSetup()
' Scale the print area to fit to one page wide.
sheet.PageSetup.FitToPage = True
sheet.PageSetup.FitToWidth = 1
sheet.PageSetup.FitToHeight = 0
' Generate worksheet columns.
GenerateColumns(sheet)
' Generate data rows containing the invoice heading.
GenerateInvoiceTitle(sheet)
' Generate data rows containing the recipient's contact information.
GenerateInvoiceBillTo(sheet)
' Generate the header row for the table of purchased products.
GenerateHeaderRow(sheet)
Dim firstDataRowIndex As Integer = sheet.CurrentRowIndex
' Generate the data row for each product in the invoice list and provide the product information: its description, quantity, unit price and so on.
For i As Integer = 0 To invoice.Items.Count - 1
GenerateDataRow(sheet, invoice.Items(i), (i + 1) = invoice.Items.Count)
Next i
' Generate the total row.
GenerateTotalRow(sheet, firstDataRowIndex)
' Generate data rows containing additional information.
GenerateInfoRow(sheet, "Make all checks payable to Vader Enterprises")
GenerateInfoRow(sheet, "If you have any questions concerning this invoice, contact Darth Vader, (111)111-1111, darth@vader.com")
' Specify the data range to be printed.
sheet.PrintArea = sheet.DataRange
End Using
End Sub
#Region "Columns"
Private Sub GenerateColumns(ByVal sheet As IXlSheet)
Dim currencyFormat As XlNumberFormat = "_([$$-409]* #,##0.00_);_([$$-409]* \(#,##0.00\);_([$$-409]* ""-""??_);_(@_)"
Dim discountFormat As XlNumberFormat = "0.00%;[Red]-0.00%;;@"
' Create the column "A" and set its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 21
End Using
' Create the column "B" and set its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 21
End Using
' Create the column "C" containing the "Description" label in the header row and adjust its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 120
' Set the horizontal and vertical alignment of cell content.
column.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Center))
End Using
' Create the column "D" and adjust its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 263
' Set the horizontal and vertical alignment of cell content.
column.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Center))
End Using
' Create the column "E" containing the "QTY" label in the header row and adjust its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 102
' Set the horizontal and vertical alignment of cell content.
column.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Center))
End Using
' Create the column "F" containing the "Unit Price" label in the header row and adjust its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 150
' Set the horizontal and vertical alignment of cell content.
column.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Right, XlVerticalAlignment.Center))
' Apply the currency number format to the column.
column.ApplyFormatting(currencyFormat)
End Using
' Create the column "G" containing the "Discount" label in the header row and adjust its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 134
' Set the horizontal and vertical alignment of cell content.
column.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Center))
' Apply the custom number format to the column.
column.ApplyFormatting(discountFormat)
End Using
' Create the column "H" containing the "Amount" label in the header row and adjust its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 174
' Set the horizontal and vertical alignment of cell content.
column.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Right, XlVerticalAlignment.Center))
' Apply the currency number format to the column.
column.ApplyFormatting(currencyFormat)
End Using
' Create the column "I" and set its width.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 21
End Using
End Sub
#End Region
#Region "Invoice Heading"
Private Sub GenerateInvoiceTitle(ByVal sheet As IXlSheet)
' Create the empty row at the top of the worksheet.
Using row As IXlRow = sheet.CreateRow()
End Using
' Create the row containing the company name and invoice label.
' Set the row height to 58 pixels and specify font attributes of cell content.
GenerateTitleRow(sheet, "Vader Enterprises", Nothing, "INVOICE", 58, titleFont, Nothing)
' Create the empty row with the default height and specific formatting.
GenerateTitleRow(sheet, Nothing, Nothing, Nothing, -1, panelFont, Nothing)
' Create the row containing the company address and invoice date.
' Set the default row height, specify font attributes and number format of cell content.
GenerateTitleRow(sheet, "123 Home Lane", "DATE", invoice.Date, -1, panelFont, "mmmm d, yyyy")
' Create the row containing the company location and invoice number.
' Set the default row height and specify font attributes of cell content.
GenerateTitleRow(sheet, "Homesville, CA, 55555", "INVOICE#", invoice.InvoiceNum, -1, panelFont, Nothing)
' Create the row containing the company phone number and service description.
' Set the default row height and specify font attributes of cell content.
GenerateTitleRow(sheet, "Phone: (111)111-1111, Fax: (111)111-1112", "FOR", "Service description", -1, panelFont, Nothing)
' Create the empty row with the default height and specific formatting.
GenerateTitleRow(sheet, Nothing, Nothing, Nothing, -1, panelFont, Nothing)
End Sub
Private Sub GenerateTitleRow(ByVal sheet As IXlSheet, ByVal info As String, ByVal name As String, ByVal value As Object, ByVal rowHeight As Integer, ByVal font As XlFont, ByVal specificFormat As XlNumberFormat)
Using row As IXlRow = sheet.CreateRow()
' Set the row height.
row.HeightInPixels = rowHeight
' Set the cell font.
row.ApplyFormatting(font)
' Create the first empty cell.
row.SkipCells(1)
' Create the blank cell with the specified formatting settings.
row.BlankCells(1, leftPanelFormatting)
' Create the third cell, assign its value and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = info
cell.ApplyFormatting(leftPanelFormatting)
End Using
' Create two blank cells with the specified formatting settings.
row.BlankCells(2, leftPanelFormatting)
' Create the cell, apply specific formatting settings to it and set the cell right border.
Using cell As IXlCell = row.CreateCell()
cell.ApplyFormatting(leftPanelFormatting)
cell.ApplyFormatting(leftPanelBorder)
End Using
' Create the cell, assign its value and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = name
cell.ApplyFormatting(rightPanelFormatting)
cell.Formatting.Alignment.Indent = 1
End Using
' Create the cell, assign its value converted from the custom object and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = XlVariantValue.FromObject(value)
cell.ApplyFormatting(rightPanelFormatting)
If specificFormat IsNot Nothing Then
cell.ApplyFormatting(specificFormat)
End If
End Using
' Create one blank cell with the specified formatting settings.
row.BlankCells(1, rightPanelFormatting)
End Using
End Sub
#End Region
#Region "Invoice BillTo"
Private Sub GenerateInvoiceBillTo(ByVal sheet As IXlSheet)
' Set the top border for the first row in the "Bill To" panel.
Dim border As New XlBorder()
' Set the top border color to white.
border.TopColor = Color.White
' Specify the medium border line style.
border.TopLineStyle = XlBorderLineStyle.Medium
' Generate worksheet rows containing buyer's contact information.
GenerateBillToRow(sheet, Nothing, Nothing, Nothing, Nothing, border)
GenerateBillToRow(sheet, "BILL TO:", invoice.Customer, "PHONE:", invoice.Phone, Nothing)
GenerateBillToRow(sheet, Nothing, invoice.Company, Nothing, Nothing, Nothing)
GenerateBillToRow(sheet, "ADDRESS:", invoice.Address, "FAX:", invoice.Fax, Nothing)
GenerateBillToRow(sheet, Nothing, invoice.Address2, Nothing, Nothing, Nothing)
GenerateBillToRow(sheet, Nothing, Nothing, Nothing, Nothing, Nothing)
End Sub
Private Sub GenerateBillToRow(ByVal sheet As IXlSheet, ByVal name1 As String, ByVal value1 As Object, ByVal name2 As String, ByVal value2 As Object, ByVal specificBorder As XlBorder)
Using row As IXlRow = sheet.CreateRow()
' Set the cell font.
row.ApplyFormatting(infoFont)
' Skip the first cell in the row.
row.SkipCells(1)
' Create the empty cell with the specified formatting settings.
Using cell As IXlCell = row.CreateCell()
cell.ApplyFormatting(infoFormatting)
' Set the cell border.
cell.ApplyFormatting(specificBorder)
End Using
' Create the cell, assign its value and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = name1
cell.ApplyFormatting(infoFormatting)
' Set the cell border.
cell.ApplyFormatting(specificBorder)
cell.Formatting.Font.Bold = True
End Using
' Create the cell, assign its value converted from the custom object and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = XlVariantValue.FromObject(value1)
cell.ApplyFormatting(infoFormatting)
' Set the cell border.
cell.ApplyFormatting(specificBorder)
End Using
' Create the cell, assign its value and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = name2
cell.ApplyFormatting(infoFormatting)
' Set the cell border.
cell.ApplyFormatting(specificBorder)
cell.Formatting.Font.Bold = True
End Using
' Create the cell, assign its value converted from the custom object and apply specific formatting settings to it.
Using cell As IXlCell = row.CreateCell()
cell.Value = XlVariantValue.FromObject(value2)
cell.ApplyFormatting(infoFormatting)
' Set the cell border.
cell.ApplyFormatting(specificBorder)
End Using
' Create three successive cells, apply specific formatting settings to them and set the cell borders.
For i As Integer = 0 To 2
Using cell As IXlCell = row.CreateCell()
cell.ApplyFormatting(infoFormatting)
cell.ApplyFormatting(specificBorder)
End Using
Next i
End Using
End Sub
#End Region
#Region "Invoice Content"
Private Sub GenerateHeaderRow(ByVal sheet As IXlSheet)
' Create an array that contains column labels for the header row.
Dim columnNames() As String = { "Description", Nothing, "QTY", "Unit Price", "Discount", "Amount" }
' Create the header row.
Using row As IXlRow = sheet.CreateRow()
' Set the row height to 28 pixels.
row.HeightInPixels = 28
' Skip the first cell in the row.
row.SkipCells(1)
' Create one blank cell with the specified formatting settings.
row.BlankCells(1, headerRowFormatting)
' Create cells that display column labels and apply specific formatting settings to them.
For Each columnName As String In columnNames
Using cell As IXlCell = row.CreateCell()
cell.Value = columnName
cell.ApplyFormatting(headerRowFormatting)
End Using
Next columnName
' Create one blank cell with the specified formatting settings.
row.BlankCells(1, headerRowFormatting)
End Using
End Sub
Private Sub GenerateDataRow(ByVal sheet As IXlSheet, ByVal item As InvoiceData, ByVal isLastRow As Boolean)
' Create the data row to display the invoice information on each product.
Using row As IXlRow = sheet.CreateRow()
' Set the row height to 28 pixels.
row.HeightInPixels = 28
' Specify formatting settings to be applied to the data rows to shade alternate rows.
Dim formatting As New XlCellFormatting()
formatting.CopyFrom(If(row.RowIndex Mod 2 = 0, evenRowFormatting, oddRowFormatting))
' Set the bottom border for the last data row.
If isLastRow Then
formatting.Border = New XlBorder()
formatting.Border.BottomColor = Color.FromArgb(89, 89, 89)
formatting.Border.BottomLineStyle = XlBorderLineStyle.Medium
End If
' Skip the first cell in the row.
row.SkipCells(1)
' Create the blank cell with the specified formatting settings.
row.BlankCells(1, formatting)
' Create the cell containing the product description.
Using cell As IXlCell = row.CreateCell()
cell.Value = item.Product
cell.ApplyFormatting(formatting)
End Using
' Create the blank cell with the specified formatting settings.
row.BlankCells(1, formatting)
' Create the cell containing the product quantity.
Using cell As IXlCell = row.CreateCell()
cell.Value = item.Qty
cell.ApplyFormatting(formatting)
End Using
' Create the cell containing the unit price.
Using cell As IXlCell = row.CreateCell()
cell.Value = item.UnitPrice
cell.ApplyFormatting(formatting)
End Using
' Create the cell containing the product discount.
Using cell As IXlCell = row.CreateCell()
cell.Value = item.Discount
cell.ApplyFormatting(formatting)
End Using
' Create the cell containing the amount.
Using cell As IXlCell = row.CreateCell()
' Set the cell value.
cell.Value = item.Qty * item.UnitPrice * (1 - item.Discount)
' Set the formula to calculate the amount per product.
cell.SetFormula(String.Format("E{0}*F{0}*(1-G{0})", cell.RowIndex + 1))
cell.ApplyFormatting(formatting)
End Using
' Create the blank cell with the specified formatting settings.
row.BlankCells(1, formatting)
End Using
End Sub
Private Sub GenerateTotalRow(ByVal sheet As IXlSheet, ByVal firstDataRowIndex As Integer)
' Skip one row before starting to generate the total row.
sheet.SkipRows(1)
' Create the total row.
Using row As IXlRow = sheet.CreateRow()
' Set the row height to 28 pixels.
row.HeightInPixels = 28
' Set font characteristics for the row cells.
row.ApplyFormatting(infoFont.Clone())
row.Formatting.Font.Bold = True
' Skip six successive cells in the total row.
row.SkipCells(6)
' Create the "Total" cell.
Using cell As IXlCell = row.CreateCell()
cell.Value = "TOTAL"
End Using
' Create the cell that displays the total amount.
Using cell As IXlCell = row.CreateCell()
' Set the formula to calculate the total amount.
cell.SetFormula(String.Format("SUM(H{0}:H{1})", firstDataRowIndex + 1, row.RowIndex - 1))
' Set the cell background color.
cell.ApplyFormatting(XlFill.SolidFill(Color.FromArgb(217, 217, 217)))
End Using
' Create the empty cell.
Using cell As IXlCell = row.CreateCell()
' Set the cell background color.
cell.ApplyFormatting(XlFill.SolidFill(Color.FromArgb(217, 217, 217)))
End Using
End Using
End Sub
Private Sub GenerateInfoRow(ByVal sheet As IXlSheet, ByVal info As String)
' Skip one row before starting to generate the row with additional information.
sheet.SkipRows(1)
' Create the row.
Using row As IXlRow = sheet.CreateRow()
' Skip the first cell in the row.
row.SkipCells(1)
' Create the cell that contains the invoice payment options and set its font attributes.
Using cell As IXlCell = row.CreateCell()
cell.Value = info
cell.ApplyFormatting(infoFont)
End Using
End Using
End Sub
#End Region
End Class
End Namespace