Free Support Forum - aspose.com

Source Code Share

Dear customers,

Unlike most software vendors, we do not charge support subscription after your purchase. That is, you can get continuous support as long as you expect while you don’t need to pay any extra bucks.

Why do we do this? We want to swap your contribution to help us to build the Aspose.Excel customer community which can really help new customers to use Aspose.Excel easily and quickly.

What is the biggest help for new users? The answer is the source code written by the existing users who have used Aspose.Excel to do various realistic projects!

So, if you love Aspose.Excel and want to support us to do it better, you’re strongly encouraged to post your source code here, either big or small, simple or complicated.

Thanks for your invaluable contribution in advance!

Function generate_excel(ByVal tableaufiche() As Fiche.Fiche, ByVal path As String, ByVal filtre As String, ByVal composante As String) As Excel

’ I create my Excel variable, with a designer file

Dim designerFile As String = path + “\model.xls”
Dim excel As New Excel()
excel.Open(designerFile)

’ I add a sheet
Dim sheet As Worksheet = excel.Worksheets.GetAt(0)

’ I add some styles for the Cells, first a style repository, and then, styles

Dim styles As Styles = excel.Styles

Dim styleIndex As Integer = styles.Add()

’ a light grey
Dim style_donnee_clair As Style = styles.GetAt(styleIndex)
style_donnee_clair.Font.Name = “Times New Roman”
style_donnee_clair.Font.IsBold = False
style_donnee_clair.Font.IsItalic = False
style_donnee_clair.ForegroundColor = System.Drawing.Color.Gainsboro

’ a dark grey
styleIndex = styles.Add()
Dim style_donnee_fonce As Style = styles.GetAt(styleIndex)
style_donnee_fonce.Font.Name = “Times New Roman”
style_donnee_fonce.Font.IsBold = False
style_donnee_fonce.Font.IsItalic = False
style_donnee_fonce.ForegroundColor = System.Drawing.Color.DarkGray

’a title style
styleIndex = styles.Add()
Dim style_titre As Style = styles.GetAt(styleIndex)
style_titre.Font.Name = “Comic Sans MS”
style_titre.Font.IsBold = False
style_titre.Font.IsItalic = True
style_titre.Font.Size = 12

’ Resizing the columns
sheet.Cells.SetColumnWidth(1, 25)
sheet.Cells.SetColumnWidth(2, 25)
sheet.Cells.SetColumnWidth(3, 40)
sheet.Cells.SetColumnWidth(4, 70)
sheet.Cells.SetColumnWidth(5, 20)
sheet.Cells.SetColumnWidth(6, 25)
sheet.Cells.SetColumnWidth(7, 30)
sheet.Cells.SetColumnWidth(8, 30)


’ little simple algo to alternate light and dark lines
Dim i As Integer
Dim j As Integer = 0

Dim clair As Boolean = True
styleIndex = styles.Add()
Dim style_donnee_alt As Style = styles.GetAt(styleIndex)

sheet.Cells.GetAt(0, 3).PutValue(composante)
sheet.Cells.GetAt(0, 3).Style = style_titre

For i = 0 To tableaufiche.Length() - 1 ‘-2

If clair Then
style_donnee_alt = style_donnee_clair
clair = False
Else
style_donnee_alt = style_donnee_fonce
clair = True
End If

’ fill the cells, and set the style
sheet.Cells.GetAt(j + 3, 1).PutValue(tableaufiche(i).Nom)
sheet.Cells.GetAt(j + 3, 1).Style = style_donnee_alt
sheet.Cells.GetAt(j + 3, 2).PutValue(tableaufiche(i).Titre)
sheet.Cells.GetAt(j + 3, 2).Style = style_donnee_alt
sheet.Cells.GetAt(j + 3, 3).PutValue(tableaufiche(i).Email(0))
sheet.Cells.GetAt(j + 3, 3).Style = style_donnee_alt
'(…)

j += 1
Next i

Return excel

End Function