Search Results for

    Show / Hide Table of Contents

    Features (VB.Net / netframework)

    Note

    This demo is available in your FlexCel installation at <FlexCel Install Folder>\samples\vb\VS2022\netframework\20.Reports\B0.Features Page and also at https:​//​github.​com/​tmssoftware/​TMS-​FlexCel.​NET-​demos/​tree/​master/​vb/​VS2022/​netframework/​Modules/​20.​Reports/​B0.​Features Page

    Overview

    This is a real world demo, showing how we create the "features" HTML sheet you can find at

    https://www.tmssoftware.com/flexcel/featuresflexcel.htm

    Concepts

    • Everything in this demo is shown in more detail somewhere else. This is just a showcase of a real application of a FlexCel report, but anyway there are some ideas worth noting.

    • We use the Image Fit tag in the image to autofit the containing cell to the height of the image. Bus as we also need to autofit the whole row, we need to do an autofit with a "Dont Shrink" option on the rows. If we didn't, when autofitting the rows the images would get outside their cells again.

    • We use Intelligent Page Breaks to have a nice PDF output.

    • As we wanted to use Access so we can distribute this demo easily to you, we did not store the images in the database. (Access is not good at storing images). So we saved the images in a folder, and used an user defined function to load them and feed the report.

    Files

    AssemblyInfo.vb

    Imports System.Reflection
    Imports System.Runtime.CompilerServices
    
    '
    ' General Information about an assembly is controlled through the following 
    ' set of attributes. Change these attribute values to modify the information
    ' associated with an assembly.
    '
    <Assembly: AssemblyTitle("")>
    <Assembly: AssemblyDescription("")>
    <Assembly: AssemblyConfiguration("")>
    <Assembly: AssemblyCompany("")>
    <Assembly: AssemblyProduct("")>
    <Assembly: AssemblyCopyright("(c) 2002 - 2014 TMS Software")>
    <Assembly: AssemblyTrademark("")>
    <Assembly: AssemblyCulture("")>
    
    '
    ' Version information for an assembly consists of the following four values:
    '
    '      Major Version
    '      Minor Version 
    '      Build Number
    '      Revision
    '
    ' You can specify all the values or you can default the Revision and Build Numbers 
    ' by using the '*' as shown below:
    
    <Assembly: AssemblyVersion("6.2.1.0")>
    
    '
    ' In order to sign your assembly you must specify a key to use. Refer to the 
    ' Microsoft .NET Framework documentation for more information on assembly signing.
    '
    ' Use the attributes below to control which key is used for signing. 
    '
    ' Notes: 
    '   (*) If no key is specified, the assembly is not signed.
    '   (*) KeyName refers to a key that has been installed in the Crypto Service
    '       Provider (CSP) on your machine. KeyFile refers to a file which contains
    '       a key.
    '   (*) If the KeyFile and the KeyName values are both specified, the 
    '       following processing occurs:
    '       (1) If the KeyName can be found in the CSP, that key is used.
    '       (2) If the KeyName does not exist and the KeyFile does exist, the key 
    '           in the KeyFile is installed into the CSP and used.
    '   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
    '       When specifying the KeyFile, the location of the KeyFile should be
    '       relative to the project output directory which is
    '       %Project Directory%\obj\<configuration>. For example, if your KeyFile is
    '       located in the project directory, you would specify the AssemblyKeyFile 
    '       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
    '   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
    '       documentation for more information on this.
    '
    <Assembly: AssemblyDelaySign(False)>
    <Assembly: AssemblyKeyFile("")>
    <Assembly: AssemblyKeyName("")>
    

    Form1.Designer.vb

    Imports System.Collections
    Imports System.ComponentModel
    Imports System.IO
    Imports System.Reflection
    Imports System.Data.OleDb
    Imports FlexCel.Core
    Imports FlexCel.XlsAdapter
    Imports FlexCel.Report
    Imports FlexCel.Render
    Imports FlexCel.Pdf
    Imports System.Globalization
    Imports System.Xml
    Namespace FeaturesPage
        Partial Public Class mainForm
            Inherits System.Windows.Forms.Form
    
            Private label1 As System.Windows.Forms.Label
            Private oleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
            Private oleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
            Private oleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand
            Private oleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand
            Private dbconnection As System.Data.OleDb.OleDbConnection
            Private categoriesAdapter As System.Data.OleDb.OleDbDataAdapter
            Private featuresAdapter As System.Data.OleDb.OleDbDataAdapter
            Private oleDbSelectCommand2 As System.Data.OleDb.OleDbCommand
            Private oleDbInsertCommand2 As System.Data.OleDb.OleDbCommand
            Private oleDbUpdateCommand2 As System.Data.OleDb.OleDbCommand
            Private oleDbDeleteCommand2 As System.Data.OleDb.OleDbCommand
            Private oleDbSelectCommand3 As System.Data.OleDb.OleDbCommand
            Private hyperlinksAdapter As System.Data.OleDb.OleDbDataAdapter
            Private components As System.ComponentModel.IContainer = Nothing
    
            ''' <summary>
            ''' Clean up any resources being used.
            ''' </summary>
            Protected Overrides Sub Dispose(ByVal disposing As Boolean)
                If disposing Then
                    If components IsNot Nothing Then
                        components.Dispose()
                    End If
                End If
                MyBase.Dispose(disposing)
            End Sub
    
            #Region "Windows Form Designer generated code"
            ''' <summary>
            ''' Required method for Designer support - do not modify
            ''' the contents of this method with the code editor.
            ''' </summary>
            Private Sub InitializeComponent()
                Dim resources As New System.ComponentModel.ComponentResourceManager(GetType(mainForm))
                Me.label1 = New System.Windows.Forms.Label()
                Me.oleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand()
                Me.dbconnection = New System.Data.OleDb.OleDbConnection()
                Me.oleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand()
                Me.oleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand()
                Me.oleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand()
                Me.categoriesAdapter = New System.Data.OleDb.OleDbDataAdapter()
                Me.featuresAdapter = New System.Data.OleDb.OleDbDataAdapter()
                Me.oleDbDeleteCommand2 = New System.Data.OleDb.OleDbCommand()
                Me.oleDbInsertCommand2 = New System.Data.OleDb.OleDbCommand()
                Me.oleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand()
                Me.oleDbUpdateCommand2 = New System.Data.OleDb.OleDbCommand()
                Me.oleDbSelectCommand3 = New System.Data.OleDb.OleDbCommand()
                Me.hyperlinksAdapter = New System.Data.OleDb.OleDbDataAdapter()
                Me.mainToolbar = New System.Windows.Forms.ToolStrip()
                Me.toolStripButton4 = New System.Windows.Forms.ToolStripButton()
                Me.toolStripButton3 = New System.Windows.Forms.ToolStripButton()
                Me.toolStripButton2 = New System.Windows.Forms.ToolStripButton()
                Me.toolStripButton1 = New System.Windows.Forms.ToolStripButton()
                Me.mainToolbar.SuspendLayout()
                Me.SuspendLayout()
                ' 
                ' label1
                ' 
                Me.label1.Location = New System.Drawing.Point(179, 69)
                Me.label1.Name = "label1"
                Me.label1.Size = New System.Drawing.Size(200, 48)
                Me.label1.TabIndex = 4
                Me.label1.Text = "Files will be saved under a ""Features"" Folder in under where the application is r" & "unning."
                ' 
                ' oleDbSelectCommand1
                ' 
                Me.oleDbSelectCommand1.CommandText = "SELECT Caption, CategoryId, CategoryName, Description FROM Categories"
                Me.oleDbSelectCommand1.Connection = Me.dbconnection
                ' 
                ' dbconnection
                ' 
                Me.dbconnection.ConnectionString = resources.GetString("dbconnection.ConnectionString")
                ' 
                ' oleDbInsertCommand1
                ' 
                Me.oleDbInsertCommand1.CommandText = "INSERT INTO Categories(Caption, CategoryName, Description) VALUES (?, ?, ?)"
                Me.oleDbInsertCommand1.Connection = Me.dbconnection
                Me.oleDbInsertCommand1.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() { _
                    New System.Data.OleDb.OleDbParameter("Caption", System.Data.OleDb.OleDbType.VarWChar, 255, "Caption"), _
                    New System.Data.OleDb.OleDbParameter("CategoryName", System.Data.OleDb.OleDbType.VarWChar, 255, "CategoryName"), _
                    New System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 0, "Description") _
                })
                ' 
                ' oleDbUpdateCommand1
                ' 
                Me.oleDbUpdateCommand1.CommandText = resources.GetString("oleDbUpdateCommand1.CommandText")
                Me.oleDbUpdateCommand1.Connection = Me.dbconnection
                Me.oleDbUpdateCommand1.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() { _
                    New System.Data.OleDb.OleDbParameter("Caption", System.Data.OleDb.OleDbType.VarWChar, 255, "Caption"), _
                    New System.Data.OleDb.OleDbParameter("CategoryName", System.Data.OleDb.OleDbType.VarWChar, 255, "CategoryName"), _
                    New System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 0, "Description"), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryId", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryId", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_Caption", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "Caption", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_Caption1", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "Caption", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryName", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryName", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryName1", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryName", System.Data.DataRowVersion.Original, Nothing) _
                })
                ' 
                ' oleDbDeleteCommand1
                ' 
                Me.oleDbDeleteCommand1.CommandText = "DELETE FROM Categories WHERE (CategoryId = ?) AND (Caption = ? OR ? IS NULL AND C" & "aption IS NULL) AND (CategoryName = ? OR ? IS NULL AND CategoryName IS NULL)"
                Me.oleDbDeleteCommand1.Connection = Me.dbconnection
                Me.oleDbDeleteCommand1.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() { _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryId", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryId", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_Caption", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "Caption", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_Caption1", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "Caption", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryName", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryName", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryName1", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryName", System.Data.DataRowVersion.Original, Nothing) _
                })
                ' 
                ' categoriesAdapter
                ' 
                Me.categoriesAdapter.DeleteCommand = Me.oleDbDeleteCommand1
                Me.categoriesAdapter.InsertCommand = Me.oleDbInsertCommand1
                Me.categoriesAdapter.SelectCommand = Me.oleDbSelectCommand1
                Me.categoriesAdapter.TableMappings.AddRange(New System.Data.Common.DataTableMapping() { New System.Data.Common.DataTableMapping("Table", "Categories", New System.Data.Common.DataColumnMapping() { New System.Data.Common.DataColumnMapping("Caption", "Caption"), New System.Data.Common.DataColumnMapping("CategoryId", "CategoryId"), New System.Data.Common.DataColumnMapping("CategoryName", "CategoryName"), New System.Data.Common.DataColumnMapping("Description", "Description")})})
                Me.categoriesAdapter.UpdateCommand = Me.oleDbUpdateCommand1
                ' 
                ' featuresAdapter
                ' 
                Me.featuresAdapter.DeleteCommand = Me.oleDbDeleteCommand2
                Me.featuresAdapter.InsertCommand = Me.oleDbInsertCommand2
                Me.featuresAdapter.SelectCommand = Me.oleDbSelectCommand2
                Me.featuresAdapter.TableMappings.AddRange(New System.Data.Common.DataTableMapping() { New System.Data.Common.DataTableMapping("Table", "Features", New System.Data.Common.DataColumnMapping() { New System.Data.Common.DataColumnMapping("Caption", "Caption"), New System.Data.Common.DataColumnMapping("CategoryId", "CategoryId"), New System.Data.Common.DataColumnMapping("Description", "Description"), New System.Data.Common.DataColumnMapping("FeaturesId", "FeaturesId")})})
                Me.featuresAdapter.UpdateCommand = Me.oleDbUpdateCommand2
                ' 
                ' oleDbDeleteCommand2
                ' 
                Me.oleDbDeleteCommand2.CommandText = "DELETE FROM Features WHERE (FeaturesId = ?) AND (Caption = ?) AND (CategoryId = ?" & ")"
                Me.oleDbDeleteCommand2.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() { _
                    New System.Data.OleDb.OleDbParameter("Original_FeaturesId", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "FeaturesId", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_Caption", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "Caption", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryId", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryId", System.Data.DataRowVersion.Original, Nothing) _
                })
                ' 
                ' oleDbInsertCommand2
                ' 
                Me.oleDbInsertCommand2.CommandText = "INSERT INTO Features(Caption, CategoryId, Description) VALUES (?, ?, ?)"
                Me.oleDbInsertCommand2.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() { _
                    New System.Data.OleDb.OleDbParameter("Caption", System.Data.OleDb.OleDbType.VarWChar, 255, "Caption"), _
                    New System.Data.OleDb.OleDbParameter("CategoryId", System.Data.OleDb.OleDbType.Integer, 0, "CategoryId"), _
                    New System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 0, "Description") _
                })
                ' 
                ' oleDbSelectCommand2
                ' 
                Me.oleDbSelectCommand2.CommandText = "SELECT Caption, CategoryId, Description, FeaturesId FROM Features order by Positi" & "onInSheet"
                Me.oleDbSelectCommand2.Connection = Me.dbconnection
                ' 
                ' oleDbUpdateCommand2
                ' 
                Me.oleDbUpdateCommand2.CommandText = "UPDATE Features SET Caption = ?, CategoryId = ?, Description = ? WHERE (FeaturesI" & "d = ?) AND (Caption = ?) AND (CategoryId = ?)"
                Me.oleDbUpdateCommand2.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() { _
                    New System.Data.OleDb.OleDbParameter("Caption", System.Data.OleDb.OleDbType.VarWChar, 255, "Caption"), _
                    New System.Data.OleDb.OleDbParameter("CategoryId", System.Data.OleDb.OleDbType.Integer, 0, "CategoryId"), _
                    New System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 0, "Description"), _
                    New System.Data.OleDb.OleDbParameter("Original_FeaturesId", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "FeaturesId", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_Caption", System.Data.OleDb.OleDbType.VarWChar, 255, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "Caption", System.Data.DataRowVersion.Original, Nothing), _
                    New System.Data.OleDb.OleDbParameter("Original_CategoryId", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, (CByte(0)), (CByte(0)), "CategoryId", System.Data.DataRowVersion.Original, Nothing) _
                })
                ' 
                ' oleDbSelectCommand3
                ' 
                Me.oleDbSelectCommand3.CommandText = "SELECT FeaturesId, HiperlinksId, LinkName, Url FROM Hyperlinks"
                Me.oleDbSelectCommand3.Connection = Me.dbconnection
                ' 
                ' hyperlinksAdapter
                ' 
                Me.hyperlinksAdapter.SelectCommand = Me.oleDbSelectCommand3
                Me.hyperlinksAdapter.TableMappings.AddRange(New System.Data.Common.DataTableMapping() { New System.Data.Common.DataTableMapping("Table", "Hyperlinks", New System.Data.Common.DataColumnMapping() { New System.Data.Common.DataColumnMapping("FeaturesId", "FeaturesId"), New System.Data.Common.DataColumnMapping("HiperlinksId", "HiperlinksId"), New System.Data.Common.DataColumnMapping("LinkName", "LinkName"), New System.Data.Common.DataColumnMapping("Url", "Url")})})
                ' 
                ' mainToolbar
                ' 
                Me.mainToolbar.Items.AddRange(New System.Windows.Forms.ToolStripItem() { Me.toolStripButton4, Me.toolStripButton3, Me.toolStripButton2, Me.toolStripButton1})
                Me.mainToolbar.Location = New System.Drawing.Point(0, 0)
                Me.mainToolbar.Name = "mainToolbar"
                Me.mainToolbar.Size = New System.Drawing.Size(528, 38)
                Me.mainToolbar.TabIndex = 5
                Me.mainToolbar.Text = "mainToolbar"
                ' 
                ' toolStripButton4
                ' 
                Me.toolStripButton4.Image = (CType(resources.GetObject("toolStripButton4.Image"), System.Drawing.Image))
                Me.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta
                Me.toolStripButton4.Name = "toolStripButton4"
                Me.toolStripButton4.Size = New System.Drawing.Size(78, 35)
                Me.toolStripButton4.Text = "Save to Excel"
                Me.toolStripButton4.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText
    '           Me.toolStripButton4.Click += New System.EventHandler(Me.btnExportExcel_Click)
                ' 
                ' toolStripButton3
                ' 
                Me.toolStripButton3.Image = (CType(resources.GetObject("toolStripButton3.Image"), System.Drawing.Image))
                Me.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta
                Me.toolStripButton3.Name = "toolStripButton3"
                Me.toolStripButton3.Size = New System.Drawing.Size(94, 35)
                Me.toolStripButton3.Text = "Export to HTML"
                Me.toolStripButton3.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText
    '           Me.toolStripButton3.Click += New System.EventHandler(Me.btnExportHtml_Click)
                ' 
                ' toolStripButton2
                ' 
                Me.toolStripButton2.Image = (CType(resources.GetObject("toolStripButton2.Image"), System.Drawing.Image))
                Me.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta
                Me.toolStripButton2.Name = "toolStripButton2"
                Me.toolStripButton2.Size = New System.Drawing.Size(82, 35)
                Me.toolStripButton2.Text = "Export to PDF"
                Me.toolStripButton2.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText
    '           Me.toolStripButton2.Click += New System.EventHandler(Me.btnExportPDF_Click)
                ' 
                ' toolStripButton1
                ' 
                Me.toolStripButton1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right
                Me.toolStripButton1.Image = (CType(resources.GetObject("toolStripButton1.Image"), System.Drawing.Image))
                Me.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta
                Me.toolStripButton1.Name = "toolStripButton1"
                Me.toolStripButton1.Size = New System.Drawing.Size(59, 35)
                Me.toolStripButton1.Text = "     E&xit     "
                Me.toolStripButton1.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText
    '           Me.toolStripButton1.Click += New System.EventHandler(Me.button2_Click)
                ' 
                ' mainForm
                ' 
                Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
                Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
                Me.ClientSize = New System.Drawing.Size(528, 126)
                Me.Controls.Add(Me.label1)
                Me.Controls.Add(Me.mainToolbar)
                Me.Name = "mainForm"
                Me.Text = "Features FlexCel"
                Me.mainToolbar.ResumeLayout(False)
                Me.mainToolbar.PerformLayout()
                Me.ResumeLayout(False)
                Me.PerformLayout()
    
            End Sub
            #End Region
    
            Private mainToolbar As ToolStrip
            Private WithEvents toolStripButton4 As ToolStripButton
            Private WithEvents toolStripButton3 As ToolStripButton
            Private WithEvents toolStripButton2 As ToolStripButton
            Private WithEvents toolStripButton1 As ToolStripButton
        End Class
    End Namespace
    

    Form1.vb

    Imports System.Collections
    Imports System.ComponentModel
    Imports System.IO
    Imports System.Reflection
    Imports System.Data.OleDb
    Imports FlexCel.Core
    Imports FlexCel.XlsAdapter
    Imports FlexCel.Report
    Imports FlexCel.Render
    Imports FlexCel.Pdf
    Imports System.Globalization
    
    Imports System.Xml
    
    
    Namespace FeaturesPage
        Partial Public Class mainForm
            Inherits System.Windows.Forms.Form
    
            Public Sub New()
                InitializeComponent()
                'initialize the db.
                dbconnection.ConnectionString = dbconnection.ConnectionString.Replace("Features.mdb", Path.Combine(DataPath, "features.mdb"))
                ResizeToolbar(mainToolbar)
                FlexCelConfig.DpiForImages = 192 'Make the exports in hidpi.
            End Sub
    
            Private Sub ResizeToolbar(ByVal toolbar As ToolStrip)
    
                Using gr As Graphics = CreateGraphics()
                    Dim xFactor As Double = gr.DpiX / 96.0
                    Dim yFactor As Double = gr.DpiY / 96.0
                    toolbar.ImageScalingSize = New Size(CInt(Fix(24 * xFactor)), CInt(Fix(24 * yFactor)))
                    toolbar.Width = 0 'force a recalc of the buttons.
                End Using
            End Sub
    
            Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles toolStripButton1.Click
                Close()
            End Sub
    
            Private Shared ReadOnly Property DataPath() As String
                Get
                    Return Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), ".."), "..") & Path.DirectorySeparatorChar
                End Get
            End Property
    
            Private ReadOnly Property ResultPath() As String
                Get
                    Dim BasePath As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                    Return Path.Combine(BasePath, "Features")
                End Get
            End Property
    
            Private Function Export(ByVal data As DataSet) As XlsFile
                Using Report As New FlexCelReport(True)
                    Report.AddTable(data)
                    Report.SetUserFunction("Images", New ImagesImp())
                    Dim Xls As New XlsFile(True)
                    Xls.Open(Path.Combine(DataPath, "Features Page.template.xls"))
    
                    Report.Run(Xls)
                    Return Xls
                End Using
    
            End Function
    
            Private Function LoadDataSet() As DataSet
                Dim Result As New DataSet()
                featuresAdapter.Fill(Result, "Features")
                categoriesAdapter.Fill(Result, "Categories")
                hyperlinksAdapter.Fill(Result, "Hyperlinks")
                Result.Relations.Add(Result.Tables("Categories").Columns("CategoryId"), Result.Tables("Features").Columns("CategoryId"))
                Result.Relations.Add(Result.Tables("Features").Columns("FeaturesId"), Result.Tables("Hyperlinks").Columns("FeaturesId"))
    
                Return Result
            End Function
    
            Private Sub btnExportExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles toolStripButton4.Click
    
                Dim XlsPath As String = Path.Combine(ResultPath, "FeaturesFlexCel.xls")
                Using data As DataSet = LoadDataSet()
                    Dim Xls As XlsFile = Export(data)
    
                    Directory.CreateDirectory(ResultPath)
                    Xls.Save(XlsPath)
                End Using
    
                If MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.Yes Then
                    Process.Start(XlsPath)
                End If
    
            End Sub
    
            Private Sub btnExportHtml_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles toolStripButton3.Click
                Dim MainHtmlPath As String = Path.Combine(ResultPath, "featuresflexcel.htm")
    
                Using data As DataSet = LoadDataSet()
                    Dim Xls As XlsFile = Export(data)
    
                    Directory.CreateDirectory(ResultPath)
                    Using html As New FlexCelHtmlExport(Xls, True)
                        html.ImageResolution = 192
                        html.ImageBackground = Color.White 'Since we are not setting html.FixIE6TransparentPngSupport, we must ensure tehre are no transparent images.
                        Dim SheetSelector As New TStandardSheetSelector(TSheetSelectorPosition.Top)
                        AddHandler SheetSelector.SheetSelectorEntry, AddressOf SheetSelector_SheetSelectorEntry
                        SheetSelector.CssGeneral.Main &= "font-family:Verdana;font-size:10pt;"
    
                        html.ExportAllVisibleSheetsAsTabs(ResultPath, "Features", ".htm", Nothing, Nothing, SheetSelector)
    
                        'Rename the first tab so it is "featuresflexcel.htm";
                        Dim Sheets() As String = html.GeneratedFiles.GetHtmlFiles()
                        File.Delete(MainHtmlPath)
                        File.Move(Sheets(0), MainHtmlPath)
    
                    End Using
                End Using
                If MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.Yes Then
                    Process.Start(MainHtmlPath)
                End If
    
    
            End Sub
    
            Private Shared Sub SheetSelector_SheetSelectorEntry(ByVal sender As Object, ByVal e As SheetSelectorEntryEventArgs)
                'We will rename the first sheet, so we need to update the links here.
                If e.ActiveSheet = 1 Then
                    e.Link = "featuresflexcel.htm"
                End If
            End Sub
    
            Private Sub btnExportPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles toolStripButton2.Click
                Dim PdfPath As String = Path.Combine(ResultPath, "FeaturesFlexCel.pdf")
    
                Using data As DataSet = LoadDataSet()
                    Dim Xls As XlsFile = Export(data)
                    Directory.CreateDirectory(ResultPath)
    
                    Using pdf As New FlexCelPdfExport(Xls, True)
                        Using pdfStream As New FileStream(PdfPath, FileMode.Create)
                            pdf.BeginExport(pdfStream)
                            pdf.FontMapping = TFontMapping.ReplaceAllFonts
    
                            pdf.Properties.Subject = "A list of FlexCel.NET features"
                            pdf.Properties.Author = "TMS Software"
                            pdf.Properties.Title = "List of FlexCel.NET features"
                            pdf.PageLayout = TPageLayout.Outlines
                            pdf.ExportAllVisibleSheets(False, "Features")
                            pdf.EndExport()
                        End Using
                    End Using
                End Using
    
                If MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.Yes Then
                    Process.Start(PdfPath)
                End If
    
            End Sub
    
    
            Private Class ImagesImp
                Inherits TFlexCelUserFunction
    
                Public Sub New()
                End Sub
    
                Public Overrides Function Evaluate(ByVal parameters() As Object) As Object
                    If parameters Is Nothing OrElse parameters.Length <> 1 Then
                        Throw New ArgumentException("Bad parameter count in call to Images() user-defined function")
                    End If
    
                    Dim ImageFilename As String = Path.Combine(Path.Combine(DataPath, "images"), "Features" & Convert.ToString(parameters(0), CultureInfo.InvariantCulture) & ".png")
                    If File.Exists(ImageFilename) Then
                        Using fs As New FileStream(ImageFilename, FileMode.Open)
                            Dim Result(CInt(fs.Length) - 1) As Byte
                            fs.Read(Result, 0, Result.Length)
                            Return Result
                        End Using
                    End If
    
                    Return Nothing
                End Function
            End Class
    
        End Class
    
    End Namespace
    

    Program.vb

    Namespace FeaturesPage
        Friend NotInheritable Class Program
    
            Private Sub New()
            End Sub
    
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
           <STAThread> _
            Shared Sub Main()
                Application.EnableVisualStyles()
                Application.SetCompatibleTextRenderingDefault(False)
                Application.Run(New mainForm())
            End Sub
        End Class
    End Namespace
    
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com