|
using System;
using GemBox.Spreadsheet;
namespace Samples
{
/// <summary>
/// TemplateUse sample.
/// </summary>
class TemplateUseCS
{
[STAThread]
static void Main(string[] args)
{
// TODO: If using GemBox.Spreadsheet Professional, put your serial key below.
// Otherwise, if you are using GemBox.Spreadsheet Free, comment out the
// following line (Free version doesn't have SetLicense method).
// SpreadsheetInfo.SetLicense("YOUR-SERIAL-KEY-HERE");
ExcelFile ef = new ExcelFile();
ef.LoadXls("..\\..\\InvoiceTemplate.xls");
FillInvoiceData( ef.Worksheets[0] );
string fileName = "Invoice14.xls";
ef.SaveXls(fileName);
TryToDisplayGeneratedFile(fileName);
}
static void FillInvoiceData(ExcelWorksheet ws)
{
ws.Cells["J5"].Value = 14;
ws.Cells["J6"].Value = new DateTime(2004,12,20);
ws.Cells["J6"].Style.NumberFormat = "m/dd/yyyy";
ws.Cells["D12"].Value = "ACME Corp";
ws.Cells["D13"].Value = "240 Old Country Road, Springfield, IL";
ws.Cells["D14"].Value = "USA";
ws.Cells["D15"].Value = "Joe Smith";
ws.Cells["E18"].Value = "6-Dec-04 until 17-Dec-04.";
for(int i=0; i<data.GetLength(0); i++)
{
ws.Cells[21+i, 1].Value = data[i,0];
ws.Cells[21+i, 1].Style.NumberFormat = "dddd, mmmm dd, yyyy";
ws.Cells[21+i, 4].Value = data[i,1];
}
ws.Cells["B36"].Value = "Payment via check.";
}
static object[,] data = new object[,]
{
{new DateTime(2004,12,6), 8},
{new DateTime(2004,12,7), 9},
{new DateTime(2004,12,8), 8},
{new DateTime(2004,12,9), 7},
{new DateTime(2004,12,10), 7},
{new DateTime(2004,12,13), 9},
{new DateTime(2004,12,14), 8},
{new DateTime(2004,12,15), 9},
{new DateTime(2004,12,16), 9},
{new DateTime(2004,12,17), 6}
};
static void TryToDisplayGeneratedFile(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch(Exception)
{
Console.WriteLine(fileName + " created in application folder.");
}
}
}
}
| |