This project has moved and is read-only. For the latest updates, please go here.
/*
   Shapes, WordArts, Pictures, 3D-Effects in Excel
   taken from Example04.cs
*/
public void Example04Main()
{
   // start excel and turn off msg boxes
   Excel.Application excelApplication = new Excel.Application();
   excelApplication.DisplayAlerts = false;

   // add a new workbook
   Excel.Workbook workBook = excelApplication.Workbooks.Add();
   Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1];

   workSheet.Cells[1, 1].Value = "these sample shapes was dynamicly created by code.";

   // create a star
   Excel.Shape starShape = workSheet.Shapes.AddShape(
MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20); // create a simple textbox Excel.Shape textBox = workSheet.Shapes.AddTextbox(
MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50); textBox.TextFrame.Characters.Text = "text"; textBox.TextFrame.Characters.Font.Size = 14; // create a wordart Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(
MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250); // create text effect Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(
MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350); // save the book string fileExtension = GetDefaultExtension(excelApplication); string workbookFile = 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(); } /// <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> private static string GetDefaultExtension(Excel.Application application) { double Version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture); if (Version >= 12.00) return ".xlsx"; else return ".xls"; }

Last edited May 14, 2012 at 5:47 AM by SebastianDotNet, version 10

Comments

No comments yet.