' Shapes, WordArts, Pictures, 3D-Effects in Excel
' taken from Example04.vb
'
Private Sub Example04Main()

  ' start excel and turn off msg boxes
  Dim excelApplication As New Excel.Application()
  excelApplication.DisplayAlerts = False

  ' add a new workbook
  Dim workBook As Excel.Workbook = excelApplication.Workbooks.Add()
  Dim workSheet As Excel.Worksheet = workBook.Worksheets(1)

  workSheet.Cells(1, 1).Value = "these sample shapes was dynamicly created by code."

  ' create a star
  Dim starShape As Excel.Shape = workSheet.Shapes.AddShape( _
MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20) 'create a simple textbox Dim textBox As Excel.Shape = workSheet.Shapes.AddTextbox( _
MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50) TextBox.TextFrame.Characters.Text = "text" TextBox.TextFrame.Characters.Font.Size = 14 ' create a wordart Dim textEffect As Excel.Shape = workSheet.Shapes.AddTextEffect( _
MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, _ MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250) ' create text effect Dim textDiagram As Excel.Shape = workSheet.Shapes.AddTextEffect( _
MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, _ MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350) ' save the book Dim fileExtension As String = GetDefaultExtension(excelApplication) Dim workbookFile As String = String.Format("{0}\Example04{1}", _
Application.StartupPath, fileExtension)
workBook.SaveAs(workbookFile, Missing.Value, Missing.Value, Missing.Value, _
Missing.Value, Missing.Value, XlSaveAsAccessMode.xlExclusive) ' close excel and dispose reference excelApplication.Quit() excelApplication.Dispose() Dim fDialog As New FinishDialog("Workbook saved.", workbookFile) fDialog.ShowDialog(Me) End Sub ''' <summary> ''' returns the valid file extension for the instance. for example ".xls" or ".xlsx" ''' </summary> ''' <param name="application">the instance</param> ''' <returns>the extension</returns> ''' <remarks></remarks> Private Function GetDefaultExtension(ByVal app As Excel.Application) As String Dim version As Double = Convert.ToDouble(app.Version, CultureInfo.InvariantCulture)
If (version >= 12.0) Then Return ".xlsx" Else Return ".xls" End If End Function

Last edited May 14, 2012 at 4:48 AM by SebastianDotNet, version 9

Comments

No comments yet.