Exporting Excel files to SVG (VB.Net / netframework)
Note
This demo is available in your FlexCel installation at <FlexCel Install Folder>\samples\vb\VS2022\netframework\25.Printing and Exporting\42.Export SVG and also at https://github.com/tmssoftware/TMS-FlexCel.NET-demos/tree/master/vb/VS2022/netframework/Modules/25.Printing and Exporting/42.Export SVG
Overview
FlexCel can natively export an Excel file to SVG (Scalar Vector Graphics)
Concepts
- When exporting to SVG you are going to get an image per page exported, so we use an action to notify the correct filename for each page.
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 FlexCel.Core
Imports FlexCel.XlsAdapter
Imports FlexCel.Render
Imports System.IO
Imports System.Text
Namespace ExportSVG
Partial Public Class mainForm
Inherits System.Windows.Forms.Form
Private openFileDialog1 As System.Windows.Forms.OpenFileDialog
Private panel1 As System.Windows.Forms.Panel
Private label1 As System.Windows.Forms.Label
Private panel3 As System.Windows.Forms.Panel
Private label12 As System.Windows.Forms.Label
Private label13 As System.Windows.Forms.Label
Private label14 As System.Windows.Forms.Label
Private edTop As System.Windows.Forms.TextBox
Private edLeft As System.Windows.Forms.TextBox
Private label15 As System.Windows.Forms.Label
Private edRight As System.Windows.Forms.TextBox
Private label16 As System.Windows.Forms.Label
Private edBottom As System.Windows.Forms.TextBox
Private label17 As System.Windows.Forms.Label
Private exportDialog As System.Windows.Forms.SaveFileDialog
Private panel8 As System.Windows.Forms.Panel
Private chFormulaText As System.Windows.Forms.CheckBox
Private chGridLines As System.Windows.Forms.CheckBox
Private label24 As System.Windows.Forms.Label
Private panel6 As System.Windows.Forms.Panel
Private label6 As System.Windows.Forms.Label
Private checkBox4 As System.Windows.Forms.CheckBox
Private cbComments As System.Windows.Forms.CheckBox
Private cbHyperlinks As System.Windows.Forms.CheckBox
Private cbImages As System.Windows.Forms.CheckBox
Private panel7 As System.Windows.Forms.Panel
Private label2 As System.Windows.Forms.Label
Private WithEvents cbExportObject As System.Windows.Forms.ComboBox
Private lblSheetToExport As System.Windows.Forms.Label
Private cbSheet As System.Windows.Forms.ComboBox
Private chPrintHeadings As System.Windows.Forms.CheckBox
Private cbHeadersFooters As System.Windows.Forms.CheckBox
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.openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
Me.panel1 = New System.Windows.Forms.Panel()
Me.panel7 = New System.Windows.Forms.Panel()
Me.cbExportObject = New System.Windows.Forms.ComboBox()
Me.lblSheetToExport = New System.Windows.Forms.Label()
Me.cbSheet = New System.Windows.Forms.ComboBox()
Me.label2 = New System.Windows.Forms.Label()
Me.panel6 = New System.Windows.Forms.Panel()
Me.cbHeadersFooters = New System.Windows.Forms.CheckBox()
Me.cbImages = New System.Windows.Forms.CheckBox()
Me.cbHyperlinks = New System.Windows.Forms.CheckBox()
Me.cbComments = New System.Windows.Forms.CheckBox()
Me.label6 = New System.Windows.Forms.Label()
Me.panel3 = New System.Windows.Forms.Panel()
Me.edBottom = New System.Windows.Forms.TextBox()
Me.label17 = New System.Windows.Forms.Label()
Me.edRight = New System.Windows.Forms.TextBox()
Me.label16 = New System.Windows.Forms.Label()
Me.edLeft = New System.Windows.Forms.TextBox()
Me.label15 = New System.Windows.Forms.Label()
Me.edTop = New System.Windows.Forms.TextBox()
Me.label14 = New System.Windows.Forms.Label()
Me.label13 = New System.Windows.Forms.Label()
Me.label12 = New System.Windows.Forms.Label()
Me.label1 = New System.Windows.Forms.Label()
Me.panel8 = New System.Windows.Forms.Panel()
Me.chPrintHeadings = New System.Windows.Forms.CheckBox()
Me.label24 = New System.Windows.Forms.Label()
Me.chFormulaText = New System.Windows.Forms.CheckBox()
Me.chGridLines = New System.Windows.Forms.CheckBox()
Me.checkBox4 = New System.Windows.Forms.CheckBox()
Me.exportDialog = New System.Windows.Forms.SaveFileDialog()
Me.mainToolbar = New System.Windows.Forms.ToolStrip()
Me.openFile = New System.Windows.Forms.ToolStripButton()
Me.export = New System.Windows.Forms.ToolStripButton()
Me.btnClose = New System.Windows.Forms.ToolStripButton()
Me.panel1.SuspendLayout()
Me.panel7.SuspendLayout()
Me.panel6.SuspendLayout()
Me.panel3.SuspendLayout()
Me.panel8.SuspendLayout()
Me.mainToolbar.SuspendLayout()
Me.SuspendLayout()
'
' openFileDialog1
'
Me.openFileDialog1.DefaultExt = "xls"
Me.openFileDialog1.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm|Excel 97/2003|*.xls|Excel 2007|*.xlsx;*.xlsm|All " & "files|*.*"
Me.openFileDialog1.Title = "Open an Excel File"
'
' panel1
'
Me.panel1.BackColor = System.Drawing.Color.White
Me.panel1.Controls.Add(Me.panel7)
Me.panel1.Controls.Add(Me.panel6)
Me.panel1.Controls.Add(Me.panel3)
Me.panel1.Controls.Add(Me.label1)
Me.panel1.Controls.Add(Me.panel8)
Me.panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.panel1.Location = New System.Drawing.Point(0, 0)
Me.panel1.Name = "panel1"
Me.panel1.Size = New System.Drawing.Size(768, 268)
Me.panel1.TabIndex = 3
'
' panel7
'
Me.panel7.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel7.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel7.Controls.Add(Me.cbExportObject)
Me.panel7.Controls.Add(Me.lblSheetToExport)
Me.panel7.Controls.Add(Me.cbSheet)
Me.panel7.Controls.Add(Me.label2)
Me.panel7.Location = New System.Drawing.Point(32, 52)
Me.panel7.Name = "panel7"
Me.panel7.Size = New System.Drawing.Size(328, 200)
Me.panel7.TabIndex = 44
'
' cbExportObject
'
Me.cbExportObject.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.cbExportObject.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbExportObject.Items.AddRange(New Object() { "All sheets", "Active Sheet:"})
Me.cbExportObject.Location = New System.Drawing.Point(8, 32)
Me.cbExportObject.Name = "cbExportObject"
Me.cbExportObject.Size = New System.Drawing.Size(293, 21)
Me.cbExportObject.TabIndex = 46
' Me.cbExportObject.SelectedIndexChanged += New System.EventHandler(Me.cbExportObject_SelectedIndexChanged)
'
' lblSheetToExport
'
Me.lblSheetToExport.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.lblSheetToExport.Location = New System.Drawing.Point(8, 66)
Me.lblSheetToExport.Name = "lblSheetToExport"
Me.lblSheetToExport.Size = New System.Drawing.Size(96, 16)
Me.lblSheetToExport.TabIndex = 45
Me.lblSheetToExport.Text = "Sheet to export:"
'
' cbSheet
'
Me.cbSheet.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.cbSheet.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbSheet.Location = New System.Drawing.Point(8, 82)
Me.cbSheet.Name = "cbSheet"
Me.cbSheet.Size = New System.Drawing.Size(294, 21)
Me.cbSheet.TabIndex = 44
'
' label2
'
Me.label2.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label2.Location = New System.Drawing.Point(8, 8)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(192, 16)
Me.label2.TabIndex = 19
Me.label2.Text = "What to Export:"
'
' panel6
'
Me.panel6.Anchor = (CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel6.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel6.Controls.Add(Me.cbHeadersFooters)
Me.panel6.Controls.Add(Me.cbImages)
Me.panel6.Controls.Add(Me.cbHyperlinks)
Me.panel6.Controls.Add(Me.cbComments)
Me.panel6.Controls.Add(Me.label6)
Me.panel6.Location = New System.Drawing.Point(366, 148)
Me.panel6.Name = "panel6"
Me.panel6.Size = New System.Drawing.Size(176, 104)
Me.panel6.TabIndex = 42
'
' cbHeadersFooters
'
Me.cbHeadersFooters.Location = New System.Drawing.Point(96, 40)
Me.cbHeadersFooters.Name = "cbHeadersFooters"
Me.cbHeadersFooters.Size = New System.Drawing.Size(72, 44)
Me.cbHeadersFooters.TabIndex = 23
Me.cbHeadersFooters.Text = "Headers / Footers"
'
' cbImages
'
Me.cbImages.Checked = True
Me.cbImages.CheckState = System.Windows.Forms.CheckState.Checked
Me.cbImages.Location = New System.Drawing.Point(16, 32)
Me.cbImages.Name = "cbImages"
Me.cbImages.Size = New System.Drawing.Size(72, 24)
Me.cbImages.TabIndex = 22
Me.cbImages.Text = "Images"
'
' cbHyperlinks
'
Me.cbHyperlinks.Checked = True
Me.cbHyperlinks.CheckState = System.Windows.Forms.CheckState.Checked
Me.cbHyperlinks.Location = New System.Drawing.Point(16, 80)
Me.cbHyperlinks.Name = "cbHyperlinks"
Me.cbHyperlinks.Size = New System.Drawing.Size(80, 24)
Me.cbHyperlinks.TabIndex = 21
Me.cbHyperlinks.Text = "HyperLinks"
'
' cbComments
'
Me.cbComments.Checked = True
Me.cbComments.CheckState = System.Windows.Forms.CheckState.Checked
Me.cbComments.Location = New System.Drawing.Point(16, 56)
Me.cbComments.Name = "cbComments"
Me.cbComments.Size = New System.Drawing.Size(80, 24)
Me.cbComments.TabIndex = 20
Me.cbComments.Text = "Comments"
'
' label6
'
Me.label6.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label6.Location = New System.Drawing.Point(8, 16)
Me.label6.Name = "label6"
Me.label6.Size = New System.Drawing.Size(192, 16)
Me.label6.TabIndex = 19
Me.label6.Text = "Objects to Export:"
'
' panel3
'
Me.panel3.Anchor = (CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel3.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(255)))), (CInt((CByte(255)))), (CInt((CByte(192)))))
Me.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel3.Controls.Add(Me.edBottom)
Me.panel3.Controls.Add(Me.label17)
Me.panel3.Controls.Add(Me.edRight)
Me.panel3.Controls.Add(Me.label16)
Me.panel3.Controls.Add(Me.edLeft)
Me.panel3.Controls.Add(Me.label15)
Me.panel3.Controls.Add(Me.edTop)
Me.panel3.Controls.Add(Me.label14)
Me.panel3.Controls.Add(Me.label13)
Me.panel3.Controls.Add(Me.label12)
Me.panel3.Location = New System.Drawing.Point(548, 52)
Me.panel3.Name = "panel3"
Me.panel3.Size = New System.Drawing.Size(208, 200)
Me.panel3.TabIndex = 30
'
' edBottom
'
Me.edBottom.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.edBottom.Location = New System.Drawing.Point(80, 136)
Me.edBottom.Name = "edBottom"
Me.edBottom.Size = New System.Drawing.Size(48, 20)
Me.edBottom.TabIndex = 26
Me.edBottom.Text = "0"
'
' label17
'
Me.label17.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label17.Location = New System.Drawing.Point(16, 160)
Me.label17.Name = "label17"
Me.label17.Size = New System.Drawing.Size(56, 16)
Me.label17.TabIndex = 25
Me.label17.Text = "Last Col:"
'
' edRight
'
Me.edRight.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.edRight.Location = New System.Drawing.Point(80, 160)
Me.edRight.Name = "edRight"
Me.edRight.Size = New System.Drawing.Size(48, 20)
Me.edRight.TabIndex = 24
Me.edRight.Text = "0"
'
' label16
'
Me.label16.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label16.Location = New System.Drawing.Point(16, 136)
Me.label16.Name = "label16"
Me.label16.Size = New System.Drawing.Size(85, 16)
Me.label16.TabIndex = 23
Me.label16.Text = "Last Row:"
'
' edLeft
'
Me.edLeft.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.edLeft.Location = New System.Drawing.Point(80, 112)
Me.edLeft.Name = "edLeft"
Me.edLeft.Size = New System.Drawing.Size(48, 20)
Me.edLeft.TabIndex = 22
Me.edLeft.Text = "0"
'
' label15
'
Me.label15.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label15.Location = New System.Drawing.Point(16, 112)
Me.label15.Name = "label15"
Me.label15.Size = New System.Drawing.Size(85, 16)
Me.label15.TabIndex = 21
Me.label15.Text = "First Col:"
'
' edTop
'
Me.edTop.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.edTop.Location = New System.Drawing.Point(80, 88)
Me.edTop.Name = "edTop"
Me.edTop.Size = New System.Drawing.Size(48, 20)
Me.edTop.TabIndex = 20
Me.edTop.Text = "0"
'
' label14
'
Me.label14.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label14.Location = New System.Drawing.Point(16, 88)
Me.label14.Name = "label14"
Me.label14.Size = New System.Drawing.Size(85, 16)
Me.label14.TabIndex = 3
Me.label14.Text = "First Row:"
'
' label13
'
Me.label13.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.label13.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label13.Location = New System.Drawing.Point(8, 32)
Me.label13.Name = "label13"
Me.label13.Size = New System.Drawing.Size(184, 32)
Me.label13.TabIndex = 2
Me.label13.Text = "If any value is <=0 all print_range will be printed"
'
' label12
'
Me.label12.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label12.Location = New System.Drawing.Point(8, 16)
Me.label12.Name = "label12"
Me.label12.Size = New System.Drawing.Size(192, 16)
Me.label12.TabIndex = 1
Me.label12.Text = "Range to Export:"
'
' label1
'
Me.label1.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label1.Location = New System.Drawing.Point(40, 16)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(80, 16)
Me.label1.TabIndex = 0
Me.label1.Text = "File to export:"
'
' panel8
'
Me.panel8.Anchor = (CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel8.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel8.Controls.Add(Me.chPrintHeadings)
Me.panel8.Controls.Add(Me.label24)
Me.panel8.Controls.Add(Me.chFormulaText)
Me.panel8.Controls.Add(Me.chGridLines)
Me.panel8.Location = New System.Drawing.Point(366, 52)
Me.panel8.Name = "panel8"
Me.panel8.Size = New System.Drawing.Size(176, 88)
Me.panel8.TabIndex = 37
'
' chPrintHeadings
'
Me.chPrintHeadings.Location = New System.Drawing.Point(16, 44)
Me.chPrintHeadings.Name = "chPrintHeadings"
Me.chPrintHeadings.Size = New System.Drawing.Size(144, 16)
Me.chPrintHeadings.TabIndex = 20
Me.chPrintHeadings.Text = "Print Headings"
'
' label24
'
Me.label24.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label24.Location = New System.Drawing.Point(8, 8)
Me.label24.Name = "label24"
Me.label24.Size = New System.Drawing.Size(192, 16)
Me.label24.TabIndex = 19
Me.label24.Text = "Export Options:"
'
' chFormulaText
'
Me.chFormulaText.Location = New System.Drawing.Point(16, 64)
Me.chFormulaText.Name = "chFormulaText"
Me.chFormulaText.Size = New System.Drawing.Size(136, 16)
Me.chFormulaText.TabIndex = 17
Me.chFormulaText.Text = "Print Formula Text"
'
' chGridLines
'
Me.chGridLines.Location = New System.Drawing.Point(16, 24)
Me.chGridLines.Name = "chGridLines"
Me.chGridLines.Size = New System.Drawing.Size(128, 16)
Me.chGridLines.TabIndex = 16
Me.chGridLines.Text = "Print Grid Lines"
'
' checkBox4
'
Me.checkBox4.Location = New System.Drawing.Point(0, 0)
Me.checkBox4.Name = "checkBox4"
Me.checkBox4.Size = New System.Drawing.Size(104, 24)
Me.checkBox4.TabIndex = 0
'
' exportDialog
'
Me.exportDialog.DefaultExt = "svg"
Me.exportDialog.Filter = "SVG Files|*.svg"
Me.exportDialog.Title = "Files will be saved as Filename_sheetname_pagenumber.svg"
'
' mainToolbar
'
Me.mainToolbar.ImageScalingSize = New System.Drawing.Size(24, 24)
Me.mainToolbar.Items.AddRange(New System.Windows.Forms.ToolStripItem() { Me.openFile, Me.export, Me.btnClose})
Me.mainToolbar.Location = New System.Drawing.Point(0, 0)
Me.mainToolbar.Name = "mainToolbar"
Me.mainToolbar.Size = New System.Drawing.Size(768, 31)
Me.mainToolbar.TabIndex = 8
'
' openFile
'
Me.openFile.Image = (CType(resources.GetObject("openFile.Image"), System.Drawing.Image))
Me.openFile.ImageTransparentColor = System.Drawing.Color.Magenta
Me.openFile.Name = "openFile"
Me.openFile.Size = New System.Drawing.Size(85, 28)
Me.openFile.Text = "Open File"
' Me.openFile.Click += New System.EventHandler(Me.openFile_Click)
'
' export
'
Me.export.Image = (CType(resources.GetObject("export.Image"), System.Drawing.Image))
Me.export.ImageTransparentColor = System.Drawing.Color.Magenta
Me.export.Name = "export"
Me.export.Size = New System.Drawing.Size(106, 28)
Me.export.Text = "Export as SVG"
' Me.export.Click += New System.EventHandler(Me.export_Click)
'
' btnClose
'
Me.btnClose.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right
Me.btnClose.Image = (CType(resources.GetObject("btnClose.Image"), System.Drawing.Image))
Me.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(53, 28)
Me.btnClose.Text = "Exit"
' Me.btnClose.Click += New System.EventHandler(Me.btnClose_Click)
'
' mainForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(768, 268)
Me.Controls.Add(Me.mainToolbar)
Me.Controls.Add(Me.panel1)
Me.Name = "mainForm"
Me.Text = "Export an Excel file to SVG"
' Me.Load += New System.EventHandler(Me.mainForm_Load)
Me.panel1.ResumeLayout(False)
Me.panel7.ResumeLayout(False)
Me.panel6.ResumeLayout(False)
Me.panel3.ResumeLayout(False)
Me.panel3.PerformLayout()
Me.panel8.ResumeLayout(False)
Me.mainToolbar.ResumeLayout(False)
Me.mainToolbar.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private mainToolbar As ToolStrip
Private WithEvents openFile As ToolStripButton
Private WithEvents export As ToolStripButton
Private WithEvents btnClose As ToolStripButton
End Class
End Namespace
Form1.vb
Imports System.Collections
Imports System.ComponentModel
Imports FlexCel.Core
Imports FlexCel.XlsAdapter
Imports FlexCel.Render
Imports System.IO
Imports System.Text
Namespace ExportSVG
''' <summary>
''' An Example on how to export to SVG.
''' </summary>
Partial Public Class mainForm
Inherits System.Windows.Forms.Form
Private SVG As New FlexCelSVGExport()
Public Sub New()
InitializeComponent()
ResizeToolbar(mainToolbar)
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 btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
Private Sub LoadSheetConfig()
Dim Xls As ExcelFile = SVG.Workbook
chGridLines.Checked = Xls.PrintGridLines
chPrintHeadings.Checked = Xls.PrintHeadings
chFormulaText.Checked = Xls.ShowFormulaText
End Sub
Private Sub openFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles openFile.Click
If openFileDialog1.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
Return
End If
SVG.Workbook = New XlsFile()
SVG.Workbook.Open(openFileDialog1.FileName)
Text = "Export: " & openFileDialog1.FileName
Dim Xls As ExcelFile = SVG.Workbook
cbSheet.Items.Clear()
For i As Integer = 1 To Xls.SheetCount
cbSheet.Items.Add(Xls.GetSheetName(i))
Next i
cbSheet.SelectedIndex = Xls.ActiveSheet - 1
LoadSheetConfig()
End Sub
Private Function CheckFileOpen() As Boolean
If SVG.Workbook Is Nothing Then
MessageBox.Show("You need to open a file first.")
Return False
End If
Return True
End Function
Private Function LoadPreferences() As Boolean
'NOTE: THERE SHOULD BE *A LOT* MORE VALIDATION OF VALUES ON THIS METHOD. (For example, validate that margins are between bounds)
' As this is a simple demo, they are not included.
Try
Dim Xls As ExcelFile = SVG.Workbook
'Note: In this demo we will only apply this things to the active sheet.
'If you want to apply the settings to all the sheets, you should loop in the sheets and change them here.
Xls.PrintGridLines = chGridLines.Checked
Xls.PrintHeadings = chPrintHeadings.Checked
Xls.ShowFormulaText = chFormulaText.Checked
SVG.PrintRangeLeft = Convert.ToInt32(edLeft.Text)
SVG.PrintRangeTop = Convert.ToInt32(edTop.Text)
SVG.PrintRangeRight = Convert.ToInt32(edRight.Text)
SVG.PrintRangeBottom = Convert.ToInt32(edBottom.Text)
SVG.HidePrintObjects = THidePrintObjects.None
If Not cbImages.Checked Then
SVG.HidePrintObjects = SVG.HidePrintObjects Or THidePrintObjects.Images
End If
If Not cbHyperlinks.Checked Then
SVG.HidePrintObjects = SVG.HidePrintObjects Or THidePrintObjects.Hyperlynks
End If
If Not cbComments.Checked Then
SVG.HidePrintObjects = SVG.HidePrintObjects Or THidePrintObjects.Comments
End If
If Not cbHeadersFooters.Checked Then
SVG.HidePrintObjects = SVG.HidePrintObjects Or THidePrintObjects.HeadersAndFooters
End If
Catch e As Exception
MessageBox.Show("Error: " & e.Message)
Return False
End Try
Return True
End Function
Private Sub cbSheet_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
SVG.Workbook.ActiveSheet = cbSheet.SelectedIndex + 1
LoadSheetConfig()
End Sub
Private Sub export_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles export.Click
If Not CheckFileOpen() Then
Return
End If
If Not LoadPreferences() Then
Return
End If
If exportDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
Return
End If
SVG.AllowOverwritingFiles = True
SVG.AllVisibleSheets = cbExportObject.SelectedIndex = 0
SVG.SaveAsImage(Sub(x) x.FileName = Path.ChangeExtension(exportDialog.FileName, "") & "_" & x.Workbook.SheetName & "_" & x.SheetPageNumber.ToString() & ".svg")
If MessageBox.Show("Do you want to open the folder with the generated files?", "Confirm", MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.Yes Then
Process.Start(Path.GetDirectoryName(exportDialog.FileName))
End If
End Sub
Private Sub mainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbExportObject.SelectedIndex = 0
End Sub
Private Sub cbExportObject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbExportObject.SelectedIndexChanged
cbSheet.Enabled = cbExportObject.SelectedIndex = 1
End Sub
End Class
End Namespace
Program.vb
Namespace ExportSVG
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