Exporting Excel files to HTML (VB.Net / netframework)
Note
This demo is available in your FlexCel installation at <FlexCel Install Folder>\samples\vb\VS2022\netframework\25.Printing and Exporting\40.Export HTML and also at https://github.com/tmssoftware/TMS-FlexCel.NET-demos/tree/master/vb/VS2022/netframework/Modules/25.Printing and Exporting/40.Export HTML
Overview
FlexCel can natively export an Excel file to HTML, in many formats like XHTML 1.1, HTML 3.2, HTML 4.1 strict or HTML 5.
Concepts
HTML is a format that makes emphasis in semantics over presentation, and because of this reason the HTML file will not be as faithful to the original file as a PDF. PDF are targeted especially for handling presentation. Anyway, the output is very similar and in many ways better (and more cross-browser) than the HTML generated by Excel itself when saving to HTML.
Among the things that are not exported you can find:
ActiveX objects
3D Charts (They will be rendered as 2d)
Not common AutoShapes (most used Autoshapes, as rectangles, rounded rectangles, ellipses, etc are exported)
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 ExportHTML
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 panel4 As System.Windows.Forms.Panel
Private label4 As System.Windows.Forms.Label
Private cbOutlook2007 As System.Windows.Forms.CheckBox
Private panel5 As System.Windows.Forms.Panel
Private label5 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 cbIe6Png 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 panel9 As System.Windows.Forms.Panel
Private label3 As System.Windows.Forms.Label
Private cbTop As System.Windows.Forms.CheckBox
Private cbLeft As System.Windows.Forms.CheckBox
Private cbRight As System.Windows.Forms.CheckBox
Private cbBottom As System.Windows.Forms.CheckBox
Private panel10 As System.Windows.Forms.Panel
Private label7 As System.Windows.Forms.Label
Private edSheetSeparator As System.Windows.Forms.TextBox
Private panel11 As System.Windows.Forms.Panel
Private label8 As System.Windows.Forms.Label
Private panel12 As System.Windows.Forms.Panel
Private WithEvents cbCss As System.Windows.Forms.CheckBox
Private edCss As System.Windows.Forms.TextBox
Private edImages As System.Windows.Forms.TextBox
Private cbHtmlVersion As System.Windows.Forms.ComboBox
Private cbFileFormat As System.Windows.Forms.ComboBox
Private label9 As System.Windows.Forms.Label
Private panel13 As System.Windows.Forms.Panel
Private edBodyStart As System.Windows.Forms.TextBox
Private label10 As System.Windows.Forms.Label
Private cbReplaceFonts As System.Windows.Forms.CheckBox
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.cbReplaceFonts = New System.Windows.Forms.CheckBox()
Me.panel13 = New System.Windows.Forms.Panel()
Me.edBodyStart = New System.Windows.Forms.TextBox()
Me.label10 = New System.Windows.Forms.Label()
Me.panel12 = New System.Windows.Forms.Panel()
Me.cbCss = New System.Windows.Forms.CheckBox()
Me.edCss = New System.Windows.Forms.TextBox()
Me.panel11 = New System.Windows.Forms.Panel()
Me.edImages = New System.Windows.Forms.TextBox()
Me.label8 = New System.Windows.Forms.Label()
Me.panel10 = New System.Windows.Forms.Panel()
Me.edSheetSeparator = New System.Windows.Forms.TextBox()
Me.label7 = New System.Windows.Forms.Label()
Me.panel9 = New System.Windows.Forms.Panel()
Me.cbBottom = New System.Windows.Forms.CheckBox()
Me.cbRight = New System.Windows.Forms.CheckBox()
Me.cbLeft = New System.Windows.Forms.CheckBox()
Me.cbTop = New System.Windows.Forms.CheckBox()
Me.label3 = New System.Windows.Forms.Label()
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.panel5 = New System.Windows.Forms.Panel()
Me.cbIe6Png = New System.Windows.Forms.CheckBox()
Me.label5 = New System.Windows.Forms.Label()
Me.cbOutlook2007 = New System.Windows.Forms.CheckBox()
Me.panel4 = New System.Windows.Forms.Panel()
Me.cbEmbedImages = New System.Windows.Forms.CheckBox()
Me.sbSVG = New System.Windows.Forms.CheckBox()
Me.label9 = New System.Windows.Forms.Label()
Me.cbFileFormat = New System.Windows.Forms.ComboBox()
Me.cbHtmlVersion = New System.Windows.Forms.ComboBox()
Me.label4 = 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.flexCelHtmlExport1 = New FlexCel.Render.FlexCelHtmlExport()
Me.mainToolbar = New System.Windows.Forms.ToolStrip()
Me.openFile = New System.Windows.Forms.ToolStripButton()
Me.export = New System.Windows.Forms.ToolStripButton()
Me.btnEmail = New System.Windows.Forms.ToolStripButton()
Me.toolStripSeparator1 = New System.Windows.Forms.ToolStripSeparator()
Me.btnClose = New System.Windows.Forms.ToolStripButton()
Me.panel1.SuspendLayout()
Me.panel13.SuspendLayout()
Me.panel12.SuspendLayout()
Me.panel11.SuspendLayout()
Me.panel10.SuspendLayout()
Me.panel9.SuspendLayout()
Me.panel7.SuspendLayout()
Me.panel6.SuspendLayout()
Me.panel5.SuspendLayout()
Me.panel4.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.cbReplaceFonts)
Me.panel1.Controls.Add(Me.panel13)
Me.panel1.Controls.Add(Me.panel12)
Me.panel1.Controls.Add(Me.panel11)
Me.panel1.Controls.Add(Me.panel10)
Me.panel1.Controls.Add(Me.panel9)
Me.panel1.Controls.Add(Me.panel7)
Me.panel1.Controls.Add(Me.panel6)
Me.panel1.Controls.Add(Me.panel5)
Me.panel1.Controls.Add(Me.panel4)
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, 696)
Me.panel1.TabIndex = 3
'
' cbReplaceFonts
'
Me.cbReplaceFonts.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.cbReplaceFonts.Location = New System.Drawing.Point(40, 634)
Me.cbReplaceFonts.Name = "cbReplaceFonts"
Me.cbReplaceFonts.Size = New System.Drawing.Size(632, 24)
Me.cbReplaceFonts.TabIndex = 50
Me.cbReplaceFonts.Text = "Replace all fonts with Arial"
'
' panel13
'
Me.panel13.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel13.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel13.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel13.Controls.Add(Me.edBodyStart)
Me.panel13.Controls.Add(Me.label10)
Me.panel13.Location = New System.Drawing.Point(32, 562)
Me.panel13.Name = "panel13"
Me.panel13.Size = New System.Drawing.Size(704, 64)
Me.panel13.TabIndex = 49
'
' edBodyStart
'
Me.edBodyStart.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edBodyStart.Location = New System.Drawing.Point(16, 32)
Me.edBodyStart.Name = "edBodyStart"
Me.edBodyStart.Size = New System.Drawing.Size(664, 20)
Me.edBodyStart.TabIndex = 20
Me.edBodyStart.Text = "<h1>Created with FlexCel</h1>"
'
' label10
'
Me.label10.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label10.Location = New System.Drawing.Point(8, 8)
Me.label10.Name = "label10"
Me.label10.Size = New System.Drawing.Size(584, 16)
Me.label10.TabIndex = 19
Me.label10.Text = "Text to add at the beginning of the file:"
'
' panel12
'
Me.panel12.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel12.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel12.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel12.Controls.Add(Me.cbCss)
Me.panel12.Controls.Add(Me.edCss)
Me.panel12.Location = New System.Drawing.Point(32, 490)
Me.panel12.Name = "panel12"
Me.panel12.Size = New System.Drawing.Size(704, 64)
Me.panel12.TabIndex = 48
'
' cbCss
'
Me.cbCss.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.cbCss.Location = New System.Drawing.Point(16, 8)
Me.cbCss.Name = "cbCss"
Me.cbCss.Size = New System.Drawing.Size(632, 24)
Me.cbCss.TabIndex = 21
Me.cbCss.Text = "Save CSS to an external file (path relative to where the html file is)"
' Me.cbCss.CheckedChanged += New System.EventHandler(Me.cbCss_CheckedChanged)
'
' edCss
'
Me.edCss.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edCss.Enabled = False
Me.edCss.Location = New System.Drawing.Point(16, 32)
Me.edCss.Name = "edCss"
Me.edCss.Size = New System.Drawing.Size(664, 20)
Me.edCss.TabIndex = 20
Me.edCss.Text = "css\test.css"
'
' panel11
'
Me.panel11.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel11.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel11.Controls.Add(Me.edImages)
Me.panel11.Controls.Add(Me.label8)
Me.panel11.Location = New System.Drawing.Point(32, 418)
Me.panel11.Name = "panel11"
Me.panel11.Size = New System.Drawing.Size(704, 64)
Me.panel11.TabIndex = 47
'
' edImages
'
Me.edImages.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edImages.Location = New System.Drawing.Point(16, 32)
Me.edImages.Name = "edImages"
Me.edImages.Size = New System.Drawing.Size(664, 20)
Me.edImages.TabIndex = 20
Me.edImages.Text = "images"
'
' label8
'
Me.label8.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label8.Location = New System.Drawing.Point(8, 8)
Me.label8.Name = "label8"
Me.label8.Size = New System.Drawing.Size(584, 16)
Me.label8.TabIndex = 19
Me.label8.Text = "Relative path for images (make it empty to save the images in the same folder as " & "the html file)"
'
' panel10
'
Me.panel10.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.panel10.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel10.Controls.Add(Me.edSheetSeparator)
Me.panel10.Controls.Add(Me.label7)
Me.panel10.Location = New System.Drawing.Point(224, 338)
Me.panel10.Name = "panel10"
Me.panel10.Size = New System.Drawing.Size(512, 72)
Me.panel10.TabIndex = 46
'
' edSheetSeparator
'
Me.edSheetSeparator.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edSheetSeparator.Location = New System.Drawing.Point(16, 32)
Me.edSheetSeparator.Name = "edSheetSeparator"
Me.edSheetSeparator.Size = New System.Drawing.Size(472, 20)
Me.edSheetSeparator.TabIndex = 20
Me.edSheetSeparator.Text = "<p><hr />Sheet <#SheetName> (<#SheetPos> of <#SheetCount>)"
'
' label7
'
Me.label7.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label7.Location = New System.Drawing.Point(8, 8)
Me.label7.Name = "label7"
Me.label7.Size = New System.Drawing.Size(480, 16)
Me.label7.TabIndex = 19
Me.label7.Text = "Sheet separator (When exporting all sheets in one file)"
'
' panel9
'
Me.panel9.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel9.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel9.Controls.Add(Me.cbBottom)
Me.panel9.Controls.Add(Me.cbRight)
Me.panel9.Controls.Add(Me.cbLeft)
Me.panel9.Controls.Add(Me.cbTop)
Me.panel9.Controls.Add(Me.label3)
Me.panel9.Location = New System.Drawing.Point(224, 266)
Me.panel9.Name = "panel9"
Me.panel9.Size = New System.Drawing.Size(288, 64)
Me.panel9.TabIndex = 45
'
' cbBottom
'
Me.cbBottom.Location = New System.Drawing.Point(216, 32)
Me.cbBottom.Name = "cbBottom"
Me.cbBottom.Size = New System.Drawing.Size(64, 16)
Me.cbBottom.TabIndex = 23
Me.cbBottom.Text = "Bottom"
'
' cbRight
'
Me.cbRight.Location = New System.Drawing.Point(144, 32)
Me.cbRight.Name = "cbRight"
Me.cbRight.Size = New System.Drawing.Size(64, 16)
Me.cbRight.TabIndex = 22
Me.cbRight.Text = "Right"
'
' cbLeft
'
Me.cbLeft.Location = New System.Drawing.Point(24, 32)
Me.cbLeft.Name = "cbLeft"
Me.cbLeft.Size = New System.Drawing.Size(48, 16)
Me.cbLeft.TabIndex = 21
Me.cbLeft.Text = "Left"
'
' cbTop
'
Me.cbTop.Checked = True
Me.cbTop.CheckState = System.Windows.Forms.CheckState.Checked
Me.cbTop.Location = New System.Drawing.Point(88, 32)
Me.cbTop.Name = "cbTop"
Me.cbTop.Size = New System.Drawing.Size(48, 16)
Me.cbTop.TabIndex = 20
Me.cbTop.Text = "Top"
'
' label3
'
Me.label3.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label3.Location = New System.Drawing.Point(8, 8)
Me.label3.Name = "label3"
Me.label3.Size = New System.Drawing.Size(192, 16)
Me.label3.TabIndex = 19
Me.label3.Text = "Tabs:"
'
' 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(704, 72)
Me.panel7.TabIndex = 44
'
' cbExportObject
'
Me.cbExportObject.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbExportObject.Items.AddRange(New Object() { "All sheets as Tabs", "All sheets as a single file", "Active Sheet:"})
Me.cbExportObject.Location = New System.Drawing.Point(8, 32)
Me.cbExportObject.Name = "cbExportObject"
Me.cbExportObject.Size = New System.Drawing.Size(248, 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(304, 8)
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(304, 32)
Me.cbSheet.Name = "cbSheet"
Me.cbSheet.Size = New System.Drawing.Size(360, 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.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(32, 226)
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:"
'
' panel5
'
Me.panel5.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel5.Controls.Add(Me.cbIe6Png)
Me.panel5.Controls.Add(Me.label5)
Me.panel5.Controls.Add(Me.cbOutlook2007)
Me.panel5.Location = New System.Drawing.Point(32, 338)
Me.panel5.Name = "panel5"
Me.panel5.Size = New System.Drawing.Size(176, 72)
Me.panel5.TabIndex = 41
'
' cbIe6Png
'
Me.cbIe6Png.Location = New System.Drawing.Point(16, 40)
Me.cbIe6Png.Name = "cbIe6Png"
Me.cbIe6Png.Size = New System.Drawing.Size(153, 24)
Me.cbIe6Png.TabIndex = 20
Me.cbIe6Png.Text = "Fix for IE6 support"
'
' label5
'
Me.label5.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label5.Location = New System.Drawing.Point(8, 8)
Me.label5.Name = "label5"
Me.label5.Size = New System.Drawing.Size(192, 16)
Me.label5.TabIndex = 19
Me.label5.Text = "Browser Fixes"
'
' cbOutlook2007
'
Me.cbOutlook2007.Location = New System.Drawing.Point(16, 24)
Me.cbOutlook2007.Name = "cbOutlook2007"
Me.cbOutlook2007.Size = New System.Drawing.Size(128, 16)
Me.cbOutlook2007.TabIndex = 16
Me.cbOutlook2007.Text = "Fix for Outlook2007"
'
' panel4
'
Me.panel4.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(224)))), (CInt((CByte(224)))), (CInt((CByte(224)))))
Me.panel4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel4.Controls.Add(Me.cbEmbedImages)
Me.panel4.Controls.Add(Me.sbSVG)
Me.panel4.Controls.Add(Me.label9)
Me.panel4.Controls.Add(Me.cbFileFormat)
Me.panel4.Controls.Add(Me.cbHtmlVersion)
Me.panel4.Controls.Add(Me.label4)
Me.panel4.Location = New System.Drawing.Point(224, 130)
Me.panel4.Name = "panel4"
Me.panel4.Size = New System.Drawing.Size(288, 128)
Me.panel4.TabIndex = 40
'
' cbEmbedImages
'
Me.cbEmbedImages.Location = New System.Drawing.Point(8, 91)
Me.cbEmbedImages.Name = "cbEmbedImages"
Me.cbEmbedImages.Size = New System.Drawing.Size(128, 28)
Me.cbEmbedImages.TabIndex = 51
Me.cbEmbedImages.Text = "Embed images"
'
' sbSVG
'
Me.sbSVG.Location = New System.Drawing.Point(141, 91)
Me.sbSVG.Name = "sbSVG"
Me.sbSVG.Size = New System.Drawing.Size(139, 28)
Me.sbSVG.TabIndex = 50
Me.sbSVG.Text = "Export images as SVG"
'
' label9
'
Me.label9.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label9.Location = New System.Drawing.Point(8, 8)
Me.label9.Name = "label9"
Me.label9.Size = New System.Drawing.Size(192, 16)
Me.label9.TabIndex = 49
Me.label9.Text = "HTML Version"
'
' cbFileFormat
'
Me.cbFileFormat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbFileFormat.Items.AddRange(New Object() { "HTML", "MHTML"})
Me.cbFileFormat.Location = New System.Drawing.Point(8, 64)
Me.cbFileFormat.Name = "cbFileFormat"
Me.cbFileFormat.Size = New System.Drawing.Size(272, 21)
Me.cbFileFormat.TabIndex = 48
'
' cbHtmlVersion
'
Me.cbHtmlVersion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbHtmlVersion.Items.AddRange(New Object() { "HTML 3.2", "HTML 4.01", "XHTML 1.1", "HTML 5"})
Me.cbHtmlVersion.Location = New System.Drawing.Point(8, 24)
Me.cbHtmlVersion.Name = "cbHtmlVersion"
Me.cbHtmlVersion.Size = New System.Drawing.Size(272, 21)
Me.cbHtmlVersion.TabIndex = 47
'
' label4
'
Me.label4.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte(0)))
Me.label4.Location = New System.Drawing.Point(5, 48)
Me.label4.Name = "label4"
Me.label4.Size = New System.Drawing.Size(192, 16)
Me.label4.TabIndex = 19
Me.label4.Text = "File Format:"
'
' 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(528, 130)
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.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(32, 130)
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 = "htm"
Me.exportDialog.Filter = "HTML files|*.htm|MHTML files|*.mht"
'
' flexCelHtmlExport1
'
Me.flexCelHtmlExport1.HeadingWidth = 50R
Me.flexCelHtmlExport1.ImageResolution = 96R
Me.flexCelHtmlExport1.UsePrintScale = False
Me.flexCelHtmlExport1.Workbook = Nothing
' Me.flexCelHtmlExport1.HtmlFont += New FlexCel.Core.HtmlFontEventHandler(Me.flexCelHtmlExport1_HtmlFont)
'
' mainToolbar
'
Me.mainToolbar.ImageScalingSize = New System.Drawing.Size(24, 24)
Me.mainToolbar.Items.AddRange(New System.Windows.Forms.ToolStripItem() { Me.openFile, Me.export, Me.btnEmail, Me.toolStripSeparator1, 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(118, 28)
Me.export.Text = "Export as HTML"
' Me.export.Click += New System.EventHandler(Me.export_Click)
'
' btnEmail
'
Me.btnEmail.Image = (CType(resources.GetObject("btnEmail.Image"), System.Drawing.Image))
Me.btnEmail.ImageTransparentColor = System.Drawing.Color.Magenta
Me.btnEmail.Name = "btnEmail"
Me.btnEmail.Size = New System.Drawing.Size(133, 28)
Me.btnEmail.Text = "Email (as MHTML)"
' Me.btnEmail.Click += New System.EventHandler(Me.btnEmail_Click)
'
' toolStripSeparator1
'
Me.toolStripSeparator1.Name = "toolStripSeparator1"
Me.toolStripSeparator1.Size = New System.Drawing.Size(6, 31)
'
' 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.button2_Click)
'
' mainForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(768, 696)
Me.Controls.Add(Me.mainToolbar)
Me.Controls.Add(Me.panel1)
Me.Name = "mainForm"
Me.Text = "Export an Excel file to HTML"
' Me.Load += New System.EventHandler(Me.mainForm_Load)
Me.panel1.ResumeLayout(False)
Me.panel13.ResumeLayout(False)
Me.panel13.PerformLayout()
Me.panel12.ResumeLayout(False)
Me.panel12.PerformLayout()
Me.panel11.ResumeLayout(False)
Me.panel11.PerformLayout()
Me.panel10.ResumeLayout(False)
Me.panel10.PerformLayout()
Me.panel9.ResumeLayout(False)
Me.panel7.ResumeLayout(False)
Me.panel6.ResumeLayout(False)
Me.panel5.ResumeLayout(False)
Me.panel4.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 btnEmail As ToolStripButton
Private toolStripSeparator1 As ToolStripSeparator
Private WithEvents btnClose As ToolStripButton
Private sbSVG As CheckBox
Private cbEmbedImages As CheckBox
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 ExportHTML
''' <summary>
''' An Example on how to export to HTML.
''' </summary>
Partial Public Class mainForm
Inherits System.Windows.Forms.Form
Private WithEvents flexCelHtmlExport1 As FlexCel.Render.FlexCelHtmlExport
Public Sub New()
InitializeComponent()
End Sub
Private MailDialog As Mailform
Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
Private Sub LoadSheetConfig()
Dim Xls As ExcelFile = flexCelHtmlExport1.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
flexCelHtmlExport1.Workbook = New XlsFile()
flexCelHtmlExport1.Workbook.Open(openFileDialog1.FileName)
Text = "Export: " & openFileDialog1.FileName
Dim Xls As ExcelFile = flexCelHtmlExport1.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 HasFileOpen() As Boolean
If flexCelHtmlExport1.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 = flexCelHtmlExport1.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
flexCelHtmlExport1.PrintRangeLeft = Convert.ToInt32(edLeft.Text)
flexCelHtmlExport1.PrintRangeTop = Convert.ToInt32(edTop.Text)
flexCelHtmlExport1.PrintRangeRight = Convert.ToInt32(edRight.Text)
flexCelHtmlExport1.PrintRangeBottom = Convert.ToInt32(edBottom.Text)
If sbSVG.Checked Then
flexCelHtmlExport1.SavedImagesFormat = THtmlImageFormat.Svg
Else
flexCelHtmlExport1.SavedImagesFormat = THtmlImageFormat.Png
End If
flexCelHtmlExport1.EmbedImages = cbEmbedImages.Checked
flexCelHtmlExport1.FixOutlook2007CssSupport = cbOutlook2007.Checked
flexCelHtmlExport1.FixIE6TransparentPngSupport = cbIe6Png.Checked
flexCelHtmlExport1.HidePrintObjects = THidePrintObjects.None
If Not cbImages.Checked Then
flexCelHtmlExport1.HidePrintObjects = flexCelHtmlExport1.HidePrintObjects Or THidePrintObjects.Images
End If
If Not cbHyperlinks.Checked Then
flexCelHtmlExport1.HidePrintObjects = flexCelHtmlExport1.HidePrintObjects Or THidePrintObjects.Hyperlynks
End If
If Not cbComments.Checked Then
flexCelHtmlExport1.HidePrintObjects = flexCelHtmlExport1.HidePrintObjects Or THidePrintObjects.Comments
End If
If Not cbHeadersFooters.Checked Then
flexCelHtmlExport1.HidePrintObjects = flexCelHtmlExport1.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)
flexCelHtmlExport1.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 HasFileOpen() Then
Return
End If
If Not LoadPreferences() Then
Return
End If
If cbFileFormat.SelectedIndex = 1 Then
flexCelHtmlExport1.HtmlFileFormat = THtmlFileFormat.MHtml
exportDialog.FilterIndex = 2
Else
flexCelHtmlExport1.HtmlFileFormat = THtmlFileFormat.Html
exportDialog.FilterIndex = 1
End If
If exportDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
Return
End If
flexCelHtmlExport1.AllowOverwritingFiles = True
Dim CssFileName As String = Nothing
If cbCss.Checked Then
CssFileName = edCss.Text
End If
Dim FileNameToOpen As String = exportDialog.FileName
Select Case cbHtmlVersion.SelectedIndex
Case 0
flexCelHtmlExport1.HtmlVersion = THtmlVersion.Html_32
Case 2
flexCelHtmlExport1.HtmlVersion = THtmlVersion.XHTML_10
Case 3
flexCelHtmlExport1.HtmlVersion = THtmlVersion.Html_5
Case Else
flexCelHtmlExport1.HtmlVersion = THtmlVersion.Html_401
End Select
If edBodyStart.Text IsNot Nothing Then
flexCelHtmlExport1.ExtraInfo.BodyStart = New String() { edBodyStart.Text }
End If
Select Case cbExportObject.SelectedIndex
Case 0
Dim SelectorPosition As TSheetSelectorPosition = TSheetSelectorPosition.None
'If in VB.NET or Delphi.NET, use "if cbTop.Checked then SelectorPosition = SelectorPosition or TSheetSelectorPosition.Top"
If cbTop.Checked Then
SelectorPosition = SelectorPosition Or TSheetSelectorPosition.Top
End If
If cbLeft.Checked Then
SelectorPosition = SelectorPosition Or TSheetSelectorPosition.Left
End If
If cbBottom.Checked Then
SelectorPosition = SelectorPosition Or TSheetSelectorPosition.Bottom
End If
If cbRight.Checked Then
SelectorPosition = SelectorPosition Or TSheetSelectorPosition.Right
End If
flexCelHtmlExport1.ExportAllVisibleSheetsAsTabs(Path.GetDirectoryName(exportDialog.FileName), Path.GetFileNameWithoutExtension(exportDialog.FileName), Path.GetExtension(exportDialog.FileName), edImages.Text, CssFileName, New TStandardSheetSelector(SelectorPosition))
FileNameToOpen = Path.Combine(Path.GetDirectoryName(exportDialog.FileName), Path.GetFileNameWithoutExtension(exportDialog.FileName))
FileNameToOpen = Path.Combine(FileNameToOpen, flexCelHtmlExport1.Workbook.SheetName)
FileNameToOpen = Path.Combine(FileNameToOpen, Path.GetExtension(exportDialog.FileName))
Case 1
flexCelHtmlExport1.ExportAllVisibleSheetsAsOneHtmlFile(exportDialog.FileName, edImages.Text, CssFileName, edSheetSeparator.Text)
Case 2
flexCelHtmlExport1.Export(exportDialog.FileName, edImages.Text, CssFileName)
Exit Select
End Select
Dim GeneratedFiles() As String = flexCelHtmlExport1.GeneratedFiles.GetHtmlFiles()
If GeneratedFiles.Length = 0 Then
MessageBox.Show("Error: No file has been generated")
Else
If MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.Yes Then
Process.Start(GeneratedFiles(0))
End If
End If
End Sub
Private Sub btnEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEmail.Click
If Not HasFileOpen() Then
Return
End If
If MailDialog Is Nothing Then
MailDialog = New Mailform()
End If
MailDialog.MainForm = Me
If Not flexCelHtmlExport1.FixOutlook2007CssSupport Then
Dim dr As DialogResult = MessageBox.Show("You have not checked ""Outlook 2007 support"". If any of your clients has Outlook express, you should turn this on." & vbLf & vbLf & "Use Outlook 2007 fix?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)
If dr = System.Windows.Forms.DialogResult.Cancel Then
Return
End If
If dr = System.Windows.Forms.DialogResult.Yes Then
cbOutlook2007.Checked = True
flexCelHtmlExport1.FixOutlook2007CssSupport = True
End If
End If
MailDialog.ShowDialog()
End Sub
Public Function GenerateMHTML() As Byte()
LoadPreferences()
flexCelHtmlExport1.HtmlFileFormat = THtmlFileFormat.MHtml
flexCelHtmlExport1.AllowOverwritingFiles = True
flexCelHtmlExport1.HtmlVersion = THtmlVersion.Html_401
If edBodyStart.Text IsNot Nothing Then
flexCelHtmlExport1.ExtraInfo.BodyStart = New String() { edBodyStart.Text }
End If
Using ms As New MemoryStream()
Using writer As New StreamWriter(ms, Encoding.UTF8)
flexCelHtmlExport1.Export(writer, flexCelHtmlExport1.Workbook.ActiveFileName, Nothing)
End Using
Return ms.ToArray()
End Using
End Function
Private Sub mainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbExportObject.SelectedIndex = 0
cbHtmlVersion.SelectedIndex = 3
cbFileFormat.SelectedIndex = 0
End Sub
Private Sub cbExportObject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbExportObject.SelectedIndexChanged
edSheetSeparator.Enabled = cbExportObject.SelectedIndex = 1
cbTop.Enabled = cbExportObject.SelectedIndex = 0
cbLeft.Enabled = cbExportObject.SelectedIndex = 0
cbRight.Enabled = cbExportObject.SelectedIndex = 0
cbBottom.Enabled = cbExportObject.SelectedIndex = 0
cbSheet.Enabled = cbExportObject.SelectedIndex = 2
End Sub
Private Sub cbCss_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbCss.CheckedChanged
edCss.Enabled = cbCss.Checked
End Sub
Private Sub flexCelHtmlExport1_HtmlFont(ByVal sender As Object, ByVal e As FlexCel.Core.HtmlFontEventArgs) Handles flexCelHtmlExport1.HtmlFont
If cbReplaceFonts.Checked Then
e.FontFamily = "arial, sans-serif"
End If
End Sub
End Class
End Namespace
Mailform.Designer.vb
Imports System.Collections
Imports System.ComponentModel
Imports FlexCel.Core
Imports System.Text
Namespace ExportHTML
Partial Public Class Mailform
Inherits System.Windows.Forms.Form
Private WithEvents btnEmail As System.Windows.Forms.Button
Private edOutServer As System.Windows.Forms.TextBox
Private label2 As System.Windows.Forms.Label
Private WithEvents edTo As System.Windows.Forms.TextBox
Private label3 As System.Windows.Forms.Label
Private WithEvents edFrom As System.Windows.Forms.TextBox
Private label4 As System.Windows.Forms.Label
Private edSubject As System.Windows.Forms.TextBox
Private label5 As System.Windows.Forms.Label
''' <summary>
''' Required designer variable.
''' </summary>
Private components As System.ComponentModel.Container = 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(Mailform))
Me.btnEmail = New System.Windows.Forms.Button()
Me.edOutServer = New System.Windows.Forms.TextBox()
Me.label2 = New System.Windows.Forms.Label()
Me.edTo = New System.Windows.Forms.TextBox()
Me.label3 = New System.Windows.Forms.Label()
Me.edFrom = New System.Windows.Forms.TextBox()
Me.label4 = New System.Windows.Forms.Label()
Me.edSubject = New System.Windows.Forms.TextBox()
Me.label5 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
' btnEmail
'
Me.btnEmail.BackColor = System.Drawing.SystemColors.Control
Me.btnEmail.Image = (CType(resources.GetObject("btnEmail.Image"), System.Drawing.Image))
Me.btnEmail.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.btnEmail.Location = New System.Drawing.Point(200, 200)
Me.btnEmail.Name = "btnEmail"
Me.btnEmail.Size = New System.Drawing.Size(70, 30)
Me.btnEmail.TabIndex = 4
Me.btnEmail.Text = "e-mail!"
Me.btnEmail.TextAlign = System.Drawing.ContentAlignment.MiddleRight
Me.btnEmail.UseVisualStyleBackColor = False
' Me.btnEmail.Click += New System.EventHandler(Me.btnEmail_Click)
'
' edOutServer
'
Me.edOutServer.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edOutServer.Location = New System.Drawing.Point(136, 144)
Me.edOutServer.Name = "edOutServer"
Me.edOutServer.Size = New System.Drawing.Size(304, 20)
Me.edOutServer.TabIndex = 3
Me.edOutServer.Text = "pop.mycompany.com"
'
' label2
'
Me.label2.Location = New System.Drawing.Point(8, 152)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(128, 16)
Me.label2.TabIndex = 10
Me.label2.Text = "Outgoing Mail Server:"
'
' edTo
'
Me.edTo.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edTo.Location = New System.Drawing.Point(136, 40)
Me.edTo.Name = "edTo"
Me.edTo.Size = New System.Drawing.Size(304, 20)
Me.edTo.TabIndex = 1
Me.edTo.Text = "user@hiscompany.com"
' Me.edTo.Leave += New System.EventHandler(Me.edTo_Leave)
'
' label3
'
Me.label3.Location = New System.Drawing.Point(16, 40)
Me.label3.Name = "label3"
Me.label3.Size = New System.Drawing.Size(128, 16)
Me.label3.TabIndex = 14
Me.label3.Text = "To:"
'
' edFrom
'
Me.edFrom.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edFrom.Location = New System.Drawing.Point(136, 8)
Me.edFrom.Name = "edFrom"
Me.edFrom.Size = New System.Drawing.Size(304, 20)
Me.edFrom.TabIndex = 0
Me.edFrom.Text = "myname@mycompany.com"
' Me.edFrom.Leave += New System.EventHandler(Me.edFrom_Leave)
'
' label4
'
Me.label4.Location = New System.Drawing.Point(16, 16)
Me.label4.Name = "label4"
Me.label4.Size = New System.Drawing.Size(120, 16)
Me.label4.TabIndex = 12
Me.label4.Text = "From:"
'
' edSubject
'
Me.edSubject.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles))
Me.edSubject.Location = New System.Drawing.Point(136, 80)
Me.edSubject.Name = "edSubject"
Me.edSubject.Size = New System.Drawing.Size(304, 20)
Me.edSubject.TabIndex = 2
Me.edSubject.Text = "A test from FlexCel"
'
' label5
'
Me.label5.Location = New System.Drawing.Point(16, 80)
Me.label5.Name = "label5"
Me.label5.Size = New System.Drawing.Size(128, 16)
Me.label5.TabIndex = 16
Me.label5.Text = "Subject:"
'
' Mailform
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(472, 246)
Me.Controls.Add(Me.edSubject)
Me.Controls.Add(Me.edTo)
Me.Controls.Add(Me.edFrom)
Me.Controls.Add(Me.edOutServer)
Me.Controls.Add(Me.label5)
Me.Controls.Add(Me.label3)
Me.Controls.Add(Me.label4)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.btnEmail)
Me.Name = "Mailform"
Me.ShowInTaskbar = False
Me.Text = "Send email..."
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
End Class
End Namespace
Mailform.vb
Imports System.Collections
Imports System.ComponentModel
Imports FlexCel.Core
Imports System.Text
Namespace ExportHTML
''' <summary>
''' Used for mailing.
''' </summary>
Partial Public Class Mailform
Inherits System.Windows.Forms.Form
Private OriginalTo As String
Private OriginalFrom As String
Private OriginalServer As String
Public Sub New()
InitializeComponent()
OriginalTo = edTo.Text
OriginalFrom = edFrom.Text
OriginalServer = edOutServer.Text
End Sub
Public MainForm As mainForm
Private Function ValidateFields() As Boolean
If OriginalTo = edTo.Text Then
MessageBox.Show("Please change the 'TO' field to the user you want to send the email")
edTo.Focus()
Return False
End If
If OriginalFrom = edFrom.Text Then
MessageBox.Show("Please change the 'From' field to the user you are using to send the email")
edFrom.Focus()
Return False
End If
If OriginalServer = edOutServer.Text Then
MessageBox.Show("Please change the 'Outgoing Mail Server' field to the pop3 server you will use to send the email.")
edOutServer.Focus()
Return False
End If
Return True
End Function
Private Sub btnEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEmail.Click
If Not ValidateFields() Then
Return
End If
If MessageBox.Show("Now we will try to send the email using the server '" & edOutServer.Text & "'" & vbLf & "Note that this is a very simple implementation, and it will not work if the SMTP server needs to login." & vbLf & "For this to work, you need a mail server that authenticates when reading the email, and then login into your normal account with your normal mail reader." & vbLf & vbLf & "If you need to authenticate in order to send mail, you will need to modify this code.", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) <> System.Windows.Forms.DialogResult.OK Then
Return
End If
Dim Mailer As New SimpleMailer()
Mailer.FromAddress = edFrom.Text
Mailer.ToAddress = edTo.Text
Mailer.Subject = edSubject.Text
Mailer.HostName = edOutServer.Text
Mailer.Port = 25
Try
Mailer.SendMail(MainForm.GenerateMHTML())
Catch ex As Exception
MessageBox.Show("Error trying to send the message: " & ex.Message)
Return
End Try
MessageBox.Show("Message has been sent. Please verify your JUNK folder or any filters, since it might be filtered as spam")
Close()
End Sub
Private Sub edFrom_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles edFrom.Leave
If OriginalTo = edTo.Text AndAlso OriginalFrom <> edFrom.Text Then
edTo.Text = edFrom.Text
End If
FillServer()
End Sub
Private Sub FillServer()
If OriginalServer = edOutServer.Text AndAlso OriginalFrom <> edFrom.Text Then
Dim AtPos As Integer = edFrom.Text.IndexOf("@")
If AtPos > 0 Then
Dim Server As String = edFrom.Text.Substring(AtPos + 1)
edOutServer.Text = "mail." & Server
End If
End If
End Sub
Private Sub edTo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles edTo.Leave
If OriginalFrom = edFrom.Text AndAlso OriginalTo <> edTo.Text Then
edFrom.Text = edTo.Text
End If
FillServer()
End Sub
End Class
End Namespace
Program.vb
Namespace ExportHTML
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
SimpleMailer.vb
Imports System.Net.Sockets
Imports System.IO
Imports System.Threading
Imports System.Globalization
Imports System.Text
Namespace ExportHTML
''' <summary>
''' IMPORTANT: This is a really simple SMTP implementation, and it is not indented to be used in production.
''' It is just mean to be use on this simple demo, as we cannot use third party solutions here.
''' You are advised to get a third party solution if you want to implement this in your application.
''' This code is based directly in RFC 2821: http://www.faqs.org/rfcs/rfc2821.html
''' </summary>
Public Class SimpleMailer
#Region "privates"
Private FHostName As String
Private FPort As Integer
Private FToAddress As String
Private FFromAddress As String
Private FSubject As String
#End Region
#Region "Public properties"
Public Property HostName() As String
Get
Return FHostName
End Get
Set(ByVal value As String)
FHostName = value
End Set
End Property
Public Property Port() As Integer
Get
Return FPort
End Get
Set(ByVal value As Integer)
FPort = value
End Set
End Property
Public Property ToAddress() As String
Get
Return FToAddress
End Get
Set(ByVal value As String)
FToAddress = value
End Set
End Property
Public Property FromAddress() As String
Get
Return FFromAddress
End Get
Set(ByVal value As String)
FFromAddress = value
End Set
End Property
Public Property Subject() As String
Get
Return FSubject
End Get
Set(ByVal value As String)
FSubject = value
End Set
End Property
#End Region
Public Sub New()
Port = 25
End Sub
Public Sub SendMail(ByVal MessageData() As Byte)
Using Tcp As New TcpClient(HostName, Port)
Using Channel As NetworkStream = Tcp.GetStream()
Try
WaitForAnswer(Channel, 220)
WriteCommand(Channel, "EHLO " & HostName)
WaitForAnswer(Channel, 250)
WriteCommand(Channel, "MAIL FROM:<" & FromAddress & ">")
WaitForAnswer(Channel, 250)
WriteCommand(Channel, "RCPT TO:<" & ToAddress & ">")
WaitForAnswer(Channel, 250)
WriteCommand(Channel, "DATA")
WaitForAnswer(Channel, 354)
SendMessage(Channel, MessageData)
WaitForAnswer(Channel, 250)
Catch e1 As SimpleMailerException
'Quit must always be performed.
WriteCommand(Channel, "QUIT")
WaitForAnswer(Channel, 221)
Return
End Try
WriteCommand(Channel, "QUIT")
WaitForAnswer(Channel, 221)
End Using
End Using
End Sub
Public Sub WaitForAnswer(ByVal Channel As NetworkStream, ByVal AnswerCode As Integer)
Dim ReadBuffer(1023) As Byte
Dim Message As String = ""
Dim numberOfBytesRead As Integer = 0
' Incoming message may be larger than the buffer size.
Do
numberOfBytesRead = Channel.Read(ReadBuffer, 0, ReadBuffer.Length)
Message &= Encoding.ASCII.GetString(ReadBuffer, 0, numberOfBytesRead)
Loop While Channel.DataAvailable
If Message.StartsWith(AnswerCode.ToString(CultureInfo.InvariantCulture)) Then
Return
End If
Throw New SimpleMailerException("Error sending email. Answer from the server: " & Message)
End Sub
Public Sub WriteCommand(ByVal Channel As NetworkStream, ByVal Command As String)
Dim WriteBuffer() As Byte = Encoding.ASCII.GetBytes(Command & vbCrLf) 'do not use Environment.NewLine here, since this is invariant and defined in the RFC
Channel.Write(WriteBuffer, 0, WriteBuffer.Length)
End Sub
Public Sub SendMessage(ByVal Channel As NetworkStream, ByVal MessageData() As Byte)
WriteCommand(Channel, "From: " & FromAddress)
WriteCommand(Channel, "To: " & ToAddress)
WriteCommand(Channel, "Subject: " & Subject)
WriteCommand(Channel, "Date: " & Date.Now.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture))
WriteEscapedData(Channel, MessageData)
WriteCommand(Channel, vbCrLf & ".") 'do not use Environment.NewLine here, since this is invariant and defined in the RFC
End Sub
''' <summary>
''' In order to send the data trough the channel, we need to detect any dot at the start of a line and replace it by ".."
''' If not, it might be interpreted as an EOF sign. We can easily loop in the MessageData array, since it only contains ASCII characters, so there are no
''' unicode colation issues.
''' </summary>
''' <param name="Channel"></param>
''' <param name="MessageData"></param>
Public Sub WriteEscapedData(ByVal Channel As NetworkStream, ByVal MessageData() As Byte)
If MessageData.Length > 0 Then
If MessageData(0) = AscW("."c) Then
Channel.WriteByte(AscW("."c))
End If
Channel.WriteByte(MessageData(0))
End If
For i As Integer = 1 To MessageData.Length - 1
If MessageData(i - 1) = AscW(ControlChars.Lf) AndAlso MessageData(i) = AscW("."c) Then
Channel.WriteByte(AscW("."c))
End If
Channel.WriteByte(MessageData(i))
Next i
End Sub
End Class
Public Class SimpleMailerException
Inherits IOException
Public Sub New(ByVal Message As String)
MyBase.New(Message)
End Sub
End Class
End Namespace