ExcelPackage - 九九乘法範例
ExcelPackage: Office Open XML Format file creation
http://www.codeplex.com/ExcelPackage
ExcelPackage provides server-side generation of Excel 2007 spreadsheets.
It is a set of classes and wrappers around the .NET 3.0 System.IO.Packaging API and the new Office Open XML file format. It extracts away the complexity of dealing with the individual XML components making it real easy to create sophisticated spreadsheets on the server.
ExcelPackage - 九九乘法範例
using System.IO;
using OfficeOpenXml;
using System.Xml;
...
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo outputDir = new DirectoryInfo(@"C:\ExcelPackageSamples\");
FileInfo newFile = new FileInfo(outputDir.FullName + @"\test.xlsx");
if (newFile.Exists)
{
newFile.Delete();
newFile = new FileInfo(outputDir.FullName + @"\test.xlsx");
}
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
xlPackage.DebugMode = true;
//九九乘法範例(1)
ExcelWorksheet worksheet1 = xlPackage.Workbook.Worksheets.Add("九九乘法範例(1)");
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
worksheet1.Cell(j, i).Value =i.ToString() + "*" + j.ToString() + "=" + (i * j).ToString();
}
xlPackage.Save();
}
}