Code samples |
The install comes with sample code written using numerous programming languages :
You'll find those samples in the /samples folder. They are provided with projects solutions and workspaces, so that you can build and run them without having to make changes.
The sample code written for Visual Studio 2003 will be automatically and seamlessly upgraded if you open them in Visual Studio 2005, 2008 or 2010.
Below are sample code pieces in VB, C#, C++ and Java meant to show how using xlsgen looks like.
The sample from the screen above is a kind of product tour, involving both simple, complex and rich formatting, as well as formulas. In order to produce the sample, the following code is required :
VB code |
' remember to reference the Excel Generator.ARsT design component Sub excelgeneration() Dim engine As CoXlsEngine Set engine = CreateObject("ExcelGenerator.ARsTDesign") Dim wbk As IXlsWorkbook Set wbk = engine.New("c:\myfile.xls") Dim wksht As IXlsWorksheet Set wksht = wbk.AddWorksheet("sheet1") ' ' create all styles ' Dim s1 As IXlsStyle Set s1 = wksht.NewStyle s1.Font.Bold = True s1.Font.Color = colorBlack s1.Font.Underlined = fontunderline_simple s1.Borders.Top.Style = border_thin s1.Borders.Top.Color = colorBlack s1.Borders.Left.Style = border_thin s1.Borders.Left.Color = colorBlack s1.Borders.Right.Style = border_thin s1.Borders.Right.Color = colorBlack s1.Apply Dim s2 As IXlsStyle Set s2 = wksht.NewStyle Dim s3 As IXlsStyle Set s3 = wksht.NewStyle s3.Font.Color = colorBlue s3.Font.Underlined = fontunderline_simple s3.Font.Bold = True s3.Font.Italic = True Dim s4 As IXlsStyle Set s4 = wksht.NewStyle s4.Pattern.BackgroundColor = &HDDDDDD s4.Borders.Left.Style = border_thin s4.Borders.Left.Color = colorBlack s4.Borders.Right.Style = border_thin s4.Borders.Right.Color = colorBlack Dim s5 As IXlsStyle Set s5 = wksht.NewStyle s5.Pattern.BackgroundColor = colorWhite s5.Borders.Left.Style = border_thin s5.Borders.Left.Color = colorBlack s5.Borders.Right.Style = border_thin s5.Borders.Right.Color = colorBlack Dim s6 As IXlsStyle Set s6 = s1.Duplicate s6.Alignment.Horizontal = halign_right Dim s7 As IXlsStyle Set s7 = wksht.NewStyle s7.Font.Name = "Symbol" s7.Font.Color = colorRed s7.Font.Bold = True Dim s8 As IXlsStyle Set s8 = wksht.NewStyle s8.Borders.Top.Style = border_thin s8.Borders.Top.Color = &HDDDDDD s8.Borders.Left.Style = border_thin s8.Borders.Left.Color = colorBlack s8.Borders.Right.Style = border_thin s8.Borders.Right.Color = colorBlack s8.Borders.Bottom.Style = border_thin s8.Borders.Bottom.Color = colorBlack Dim s9 As IXlsStyle Set s9 = wksht.NewStyle s9.Font.Name = "Symbol" Dim s10 As IXlsStyle Set s10 = s5.Duplicate s10.Alignment.Horizontal = halign_right Dim s11 As IXlsStyle Set s11 = s8.Duplicate s11.Format = "##.00000" ' ' create the table ' s1.Apply wksht.Label(3, 3) = "Name" s4.Apply Dim rl1 As IXlsRichLabel Set rl1 = wksht.NewRichLabel rl1.Label "Carl ", s2 rl1.Label "x-ray", s3 wksht.RichLabel(4, 3) = rl1 s5.Apply Dim rl2 As IXlsRichLabel Set rl2 = wksht.NewRichLabel rl2.Label "Johnny ", s2 rl2.Label "waver", s3 wksht.RichLabel(5, 3) = rl2 s4.Apply Dim rl3 As IXlsRichLabel Set rl3 = wksht.NewRichLabel rl3.Label "Myriam ", s2 rl3.Label "sooshie", s3 wksht.RichLabel(6, 3) = rl3 s5.Apply Dim rl4 As IXlsRichLabel Set rl4 = wksht.NewRichLabel rl4.Label "Pete ", s2 rl4.Label "blomb", s3 wksht.RichLabel(7, 3) = rl4 s8.Apply Dim rl5 As IXlsRichLabel Set rl5 = wksht.NewRichLabel rl5.Label "Average ", s2 Dim sArrowSymbol As String sArrowSymbol = String$(1, 174) ' 174 = ascii code rl5.Label sArrowSymbol, s9 wksht.RichLabel(8, 3) = rl5 ' now for the second column s6.Apply wksht.Label(3, 4) = "Score" s4.Apply wksht.Number(4, 4) = 30 s5.Apply wksht.Number(5, 4) = 40 s4.Apply wksht.Number(6, 4) = 60 s10.Apply Dim rl6 As IXlsRichLabel Set rl6 = wksht.NewRichLabel rl6.Label "5 ", s2 Dim sUpSymbol As String sUpSymbol = String$(1, 68) ' 68 = ascii code rl6.Label sUpSymbol, s7 wksht.RichLabel(7, 4) = rl6 s11.Apply wksht.Formula(8, 4) = "=AVERAGE(R4C4:R6C4)" wksht.ColWidth(3) = 17 wksht.ColWidth(4) = 10 wbk.Close Set engine = Nothing End Sub |
The sample from the screen above is a kind of product tour, involving both simple, complex and rich formatting, as well as formulas. In order to produce the sample, the following code is required :
C# code |
using xlsgen; xlsgen.CoXlsEngine engine = new xlsgen.CoXlsEngine(); IXlsWorkbook wbk = engine.New( @"c:\myfile.xls" ); IXlsWorksheet wksht = wbk.AddWorksheet( "sheet1" ); // // create all styles // IXlsStyle s1 = wksht.NewStyle(); s1.Font.Bold = 1; s1.Font.Color = (int) xlsgen.enumColorPalette.colorBlack; s1.Font.Underlined = xlsgen.enumUnderline.fontunderline_simple; s1.Borders.Top.Style = xlsgen.enumBorderStyle.border_thin; s1.Borders.Top.Color = (int) xlsgen.enumColorPalette.colorBlack; s1.Borders.Left.Style = xlsgen.enumBorderStyle.border_thin; s1.Borders.Left.Color = (int) xlsgen.enumColorPalette.colorBlack; s1.Borders.Right.Style = xlsgen.enumBorderStyle.border_thin; s1.Borders.Right.Color = (int) xlsgen.enumColorPalette.colorBlack; s1.Apply(); IXlsStyle s2 = wksht.NewStyle(); IXlsStyle s3 = wksht.NewStyle(); s3.Font.Color = (int) xlsgen.enumColorPalette.colorBlue; s3.Font.Underlined = xlsgen.enumUnderline.fontunderline_simple; s3.Font.Bold = 1; s3.Font.Italic = 1; IXlsStyle s4 = wksht.NewStyle(); s4.Pattern.BackgroundColor = 0xDDDDDD; s4.Borders.Left.Style = xlsgen.enumBorderStyle.border_thin; s4.Borders.Left.Color = (int) xlsgen.enumColorPalette.colorBlack; s4.Borders.Right.Style = xlsgen.enumBorderStyle.border_thin; s4.Borders.Right.Color = (int) xlsgen.enumColorPalette.colorBlack; IXlsStyle s5 = wksht.NewStyle(); s5.Pattern.BackgroundColor = (int) xlsgen.enumColorPalette.colorWhite; s5.Borders.Left.Style = xlsgen.enumBorderStyle.border_thin; s5.Borders.Left.Color = (int) xlsgen.enumColorPalette.colorBlack; s5.Borders.Right.Style = xlsgen.enumBorderStyle.border_thin; s5.Borders.Right.Color = (int) xlsgen.enumColorPalette.colorBlack; IXlsStyle s6 = s1.Duplicate(); s6.Alignment.Horizontal = xlsgen.enumHorizontalAlignment.halign_right; IXlsStyle s7 = wksht.NewStyle(); s7.Font.Name = "Symbol"; s7.Font.Color = (int) xlsgen.enumColorPalette.colorRed; s7.Font.Bold = 1; IXlsStyle s8 = wksht.NewStyle(); s8.Borders.Top.Style = xlsgen.enumBorderStyle.border_thin; s8.Borders.Top.Color = 0xDDDDDD; s8.Borders.Left.Style = xlsgen.enumBorderStyle.border_thin; s8.Borders.Left.Color = (int) xlsgen.enumColorPalette.colorBlack; s8.Borders.Right.Style = xlsgen.enumBorderStyle.border_thin; s8.Borders.Right.Color = (int) xlsgen.enumColorPalette.colorBlack; s8.Borders.Bottom.Style = xlsgen.enumBorderStyle.border_thin; s8.Borders.Bottom.Color = (int) xlsgen.enumColorPalette.colorBlack; IXlsStyle s9 = wksht.NewStyle(); s9.Font.Name = "Symbol"; IXlsStyle s10 = s5.Duplicate(); s10.Alignment.Horizontal = xlsgen.enumHorizontalAlignment.halign_right; IXlsStyle s11 = s8.Duplicate(); s11.Format = "##.00000"; // // create the table // s1.Apply(); wksht.set_Label(3,3, "Name"); s4.Apply(); IXlsRichLabel rl1 = wksht.NewRichLabel(); rl1.Label( "Carl ", s2); rl1.Label( "x-ray", s3); wksht.set_RichLabel(4,3, rl1); s5.Apply(); IXlsRichLabel rl2 = wksht.NewRichLabel(); rl2.Label( "Johnny ", s2); rl2.Label( "waver", s3); wksht.set_RichLabel(5,3, rl2); s4.Apply(); IXlsRichLabel rl3 = wksht.NewRichLabel(); rl3.Label( "Myriam ", s2); rl3.Label( "sooshie", s3); wksht.set_RichLabel(6,3, rl3); s5.Apply(); IXlsRichLabel rl4 = wksht.NewRichLabel(); rl4.Label( "Pete ", s2); rl4.Label( "blomb", s3); wksht.set_RichLabel(7,3, rl4); s8.Apply(); IXlsRichLabel rl5 = wksht.NewRichLabel(); rl5.Label( "Average ", s2); String sArrowSymbol = new String('\xAE',1); // arrow symbol rl5.Label( sArrowSymbol, s9); wksht.set_RichLabel(8,3, rl5); // now for the second column s6.Apply(); wksht.set_Label(3,4, "Score"); s4.Apply(); wksht.set_Number(4,4, 30); s5.Apply(); wksht.set_Number(5,4, 40); s4.Apply(); wksht.set_Number(6,4, 60); s10.Apply(); IXlsRichLabel rl6 = wksht.NewRichLabel(); rl6.Label( "5 ", s2); String sUpSymbol = new String('\x44',1); rl6.Label( sUpSymbol, s7); wksht.set_RichLabel(7,4, rl6); s11.Apply(); wksht.set_Formula(8,4, "=AVERAGE(R4C4:R6C4)"); wksht.set_ColWidth(3, 17); wksht.set_ColWidth(4, 10); wbk.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(engine); |
The sample from the screen above is a kind of product tour, involving both simple, complex and rich formatting, as well as formulas. In order to produce the sample, the following code is required :
C++ code |
#import "xlsgen.dll" ::CoInitialize(NULL); { xlsgen::IXlsEnginePtr engine( __uuidof(xlsgen::CoXlsEngine) ); xlsgen::IXlsWorkbookPtr wbk; wbk = engine->New( L"c:\\myfile.xls" ); xlsgen::IXlsWorksheetPtr wksht; wksht = wbk->AddWorksheet( L"sheet1" ); // // create all styles // xlsgen::IXlsStylePtr s1 = wksht->NewStyle(); s1->Font->Bold = TRUE; s1->Font->Color = xlsgen::colorBlack; s1->Font->Underlined = xlsgen::fontunderline_simple; s1->Borders->Top->Style = xlsgen::border_thin; s1->Borders->Top->Color = xlsgen::colorBlack; s1->Borders->Left->Style = xlsgen::border_thin; s1->Borders->Left->Color = xlsgen::colorBlack; s1->Borders->Right->Style = xlsgen::border_thin; s1->Borders->Right->Color = xlsgen::colorBlack; s1->Apply(); xlsgen::IXlsStylePtr s2 = wksht->NewStyle(); xlsgen::IXlsStylePtr s3 = wksht->NewStyle(); s3->Font->Color = xlsgen::colorBlue; s3->Font->Underlined = xlsgen::fontunderline_simple; s3->Font->Bold = TRUE; s3->Font->Italic = TRUE; xlsgen::IXlsStylePtr s4 = wksht->NewStyle(); s4->Pattern->BackgroundColor = 0xDDDDDD; s4->Borders->Left->Style = xlsgen::border_thin; s4->Borders->Left->Color = xlsgen::colorBlack; s4->Borders->Right->Style = xlsgen::border_thin; s4->Borders->Right->Color = xlsgen::colorBlack; xlsgen::IXlsStylePtr s5 = wksht->NewStyle(); s5->Pattern->BackgroundColor = xlsgen::colorWhite; s5->Borders->Left->Style = xlsgen::border_thin; s5->Borders->Left->Color = xlsgen::colorBlack; s5->Borders->Right->Style = xlsgen::border_thin; s5->Borders->Right->Color = xlsgen::colorBlack; xlsgen::IXlsStylePtr s6 = s1->Duplicate(); s6->Alignment->Horizontal = xlsgen::halign_right; xlsgen::IXlsStylePtr s7 = wksht->NewStyle(); s7->Font->Name = L"Symbol"; s7->Font->Color = xlsgen::colorRed; s7->Font->Bold = TRUE; xlsgen::IXlsStylePtr s8 = wksht->NewStyle(); s8->Borders->Top->Style = xlsgen::border_thin; s8->Borders->Top->Color = 0xDDDDDD; s8->Borders->Left->Style = xlsgen::border_thin; s8->Borders->Left->Color = xlsgen::colorBlack; s8->Borders->Right->Style = xlsgen::border_thin; s8->Borders->Right->Color = xlsgen::colorBlack; s8->Borders->Bottom->Style = xlsgen::border_thin; s8->Borders->Bottom->Color = xlsgen::colorBlack; xlsgen::IXlsStylePtr s9 = wksht->NewStyle(); s9->Font->Name = L"Symbol"; xlsgen::IXlsStylePtr s10 = s5->Duplicate(); s10->Alignment->Horizontal = xlsgen::halign_right; xlsgen::IXlsStylePtr s11 = s8->Duplicate(); s11->Format = L"##.00000"; // // create the table // s1->Apply(); wksht->Label[3][3] = L"Name"; s4->Apply(); xlsgen::IXlsRichLabelPtr rl1 = wksht->NewRichLabel(); rl1->Label( L"Carl ", s2); rl1->Label( L"x-ray", s3); wksht->RichLabel[4][3] = rl1; s5->Apply(); xlsgen::IXlsRichLabelPtr rl2 = wksht->NewRichLabel(); rl2->Label( L"Johnny ", s2); rl2->Label( L"waver", s3); wksht->RichLabel[5][3] = rl2; s4->Apply(); xlsgen::IXlsRichLabelPtr rl3 = wksht->NewRichLabel(); rl3->Label( L"Myriam ", s2); rl3->Label( L"sooshie", s3); wksht->RichLabel[6][3] = rl3; s5->Apply(); xlsgen::IXlsRichLabelPtr rl4 = wksht->NewRichLabel(); rl4->Label( L"Pete ", s2); rl4->Label( L"blomb", s3); wksht->RichLabel[7][3] = rl4; s8->Apply(); xlsgen::IXlsRichLabelPtr rl5 = wksht->NewRichLabel(); rl5->Label( L"Average ", s2); rl5->Label( L"\xAE", s9); // 0xAE = 174 = ascii code of arrow wksht->RichLabel[8][3] = rl5; // now for the second column s6->Apply(); wksht->Label[3][4] = L"Score"; s4->Apply(); wksht->Number[4][4] = 30; s5->Apply(); wksht->Number[5][4] = 40; s4->Apply(); wksht->Number[6][4] = 60; s10->Apply(); xlsgen::IXlsRichLabelPtr rl6 = wksht->NewRichLabel(); rl6->Label( L"5 ", s2); rl6->Label( L"\x44", s7); // wksht->RichLabel[7][4] = rl6; s11->Apply(); wksht->Formula[8][4] = L"=AVERAGE(R4C4:R6C4)"; wksht->ColWidth[3] = 17; wksht->ColWidth[4] = 10; wbk->Close(); } ::CoUninitialize(); |
The sample from the screen above is a kind of product tour, involving both simple, complex and rich formatting, as well as formulas. In order to produce the sample, the following code is required :
Java code |
import xlsgen.*; // // To use this code, remember to add files xlsgen.jar and // xlsgen_jproxy.dll in your project references (if you are using an IDE) // and application folder for build-time and run-time respectively. // // How to build this source code file : // // Assuming this source code file is called test.java, in order to build the project // .copy file xlsgen.jar in some folder // .and use the following commands : // set PATH=%JAVA_HOME%;%PATH% // javac -classpath .;<path>\xlsgen.jar test.java // // // How to run this application : // // .use the following command : // java -classpath .;<path>\xlsgen.jar test // // Note : starting the xlsgen component is done by indicating the path to // file xlsgen.dll in the XlsEngine constructor. See below. This can alternatively // be a plain "xlsgen.dll" statement if you put a copy of the file in the // application folder. It can also be a relative path (as in ./../../../xlsgen.dll) // or an absolute path. // class simple { public static void main(String[] args) { XlsEngine engine = new XlsEngine("./../../../xlsgen.dll"); XlsWorkbook workbook = engine.New("sample3.xls"); XlsWorksheet wksht = workbook.AddWorksheet("sheet1"); // // create all styles // XlsStyle s1 = wksht.NewStyle(); { XlsFont font = s1.getFont(); font.putBold(true); font.putColor( xlsgen.colorBlack ); font.putUnderlined( xlsgen.fontunderline_simple ); XlsBorders borders = s1.getBorders(); borders.getTop().putColor( xlsgen.colorBlack); borders.getTop().putStyle( xlsgen.border_thin); borders.getLeft().putColor( xlsgen.colorBlack); borders.getLeft().putStyle( xlsgen.border_thin); borders.getRight().putColor( xlsgen.colorBlack); borders.getRight().putStyle( xlsgen.border_thin); } s1.Apply(); XlsStyle s2 = wksht.NewStyle(); XlsStyle s3 = wksht.NewStyle(); { XlsFont font = s3.getFont(); font.putBold(true); font.putItalic(true); font.putColor( xlsgen.colorBlue ); font.putUnderlined( xlsgen.fontunderline_simple ); } XlsStyle s4 = wksht.NewStyle(); { XlsBorders borders = s4.getBorders(); borders.getLeft().putColor( xlsgen.colorBlack); borders.getLeft().putStyle( xlsgen.border_thin); borders.getRight().putColor( xlsgen.colorBlack); borders.getRight().putStyle( xlsgen.border_thin); s4.getPattern().putBackgroundColor(0xDDDDDD); } XlsStyle s5 = wksht.NewStyle(); { XlsBorders borders = s5.getBorders(); borders.getLeft().putColor( xlsgen.colorBlack); borders.getLeft().putStyle( xlsgen.border_thin); borders.getRight().putColor( xlsgen.colorBlack); borders.getRight().putStyle( xlsgen.border_thin); s5.getPattern().putBackgroundColor( xlsgen.colorWhite ); } XlsStyle s6 = s1.Duplicate(); s6.getAlignment().putHorizontal( xlsgen.halign_right ); XlsStyle s7 = wksht.NewStyle(); { XlsFont font = s7.getFont(); font.putBold(true); font.putColor( xlsgen.colorRed ); font.putName( "Symbol" ); } XlsStyle s8 = wksht.NewStyle(); { XlsBorders borders = s8.getBorders(); borders.getTop().putColor( 0xDDDDDD ); borders.getTop().putStyle( xlsgen.border_thin ); borders.getLeft().putColor( xlsgen.colorBlack ); borders.getLeft().putStyle( xlsgen.border_thin ); borders.getRight().putColor( xlsgen.colorBlack ); borders.getRight().putStyle( xlsgen.border_thin ); borders.getBottom().putColor( xlsgen.colorBlack ); borders.getBottom().putStyle( xlsgen.border_thin ); } XlsStyle s9 = wksht.NewStyle(); s9.getFont().putName( "Symbol" ); XlsStyle s10 = s5.Duplicate(); s10.getAlignment().putHorizontal( xlsgen.halign_right ); XlsStyle s11 = s8.Duplicate(); s11.putFormat("##.00000"); // // create the table // s1.Apply(); wksht.putLabel(3, 3, "Name"); s4.Apply(); XlsRichLabel rl1 = wksht.NewRichLabel(); rl1.Label("Carl ", s2); rl1.Label("x-ray", s3); wksht.putRichLabel(4, 3, rl1); s5.Apply(); XlsRichLabel rl2 = wksht.NewRichLabel(); rl2.Label("Johnny ", s2); rl2.Label("waver", s3); wksht.putRichLabel(5, 3, rl2); s4.Apply(); XlsRichLabel rl3 = wksht.NewRichLabel(); rl3.Label("Myriam ", s2); rl3.Label("sooshie", s3); wksht.putRichLabel(6, 3, rl3); s5.Apply(); XlsRichLabel rl4 = wksht.NewRichLabel(); rl4.Label("Pete ", s2); rl4.Label("blomb", s3); wksht.putRichLabel(7, 3, rl4); s8.Apply(); XlsRichLabel rl5 = wksht.NewRichLabel(); rl5.Label("Average ", s2); rl5.Label(new String(new char [] {0xAE}), s9); // 0xAE = 174 = ascii code of arrow wksht.putRichLabel(8, 3, rl5); // now for the second column s6.Apply(); wksht.putLabel(3, 4, "Score"); s4.Apply(); wksht.putNumber(4, 4, 30); s5.Apply(); wksht.putNumber(5, 4, 40); s4.Apply(); wksht.putNumber(6, 4, 60); s10.Apply(); XlsRichLabel rl6 = wksht.NewRichLabel(); rl6.Label("5", s2); rl6.Label(new String(new char [] {0x44}), s7); wksht.putRichLabel(7, 4, rl6); s11.Apply(); wksht.putFormula(8, 4, "=AVERAGE(R4C4:R6C4)"); wksht.putColWidth(3, 17); wksht.putColWidth(4, 10); workbook.Close(); } } |