本文详细讲解如何设置Aspose.Cells的授权与使用,阅读时间2分钟。
授权帮助类
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace AsposeCellsDemo
{
public sealed class AsposeLicenseHelper
{
public static void SetCellLicense()
{
var txtLicense = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "License.txt");
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(txtLicense));
new Aspose.Cells.License().SetLicense(memoryStream);
}
}
}
加载授权
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AsposeCellsDemo
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//设置授权
AsposeLicenseHelper.SetCellLicense();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
简单使用
private void bExport_Click(object sender, EventArgs e)
{
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Cells[0, 0].PutValue("测试");
workbook.Save(AppDomain.CurrentDomain.BaseDirectory + "test.xlsx", SaveFormat.Xlsx);
}