惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
P
Privacy International News Feed
T
Tenable Blog
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
月光博客
月光博客
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
Security Latest
Security Latest
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
I
InfoQ
Spread Privacy
Spread Privacy
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
博客园_首页
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
Latest news
Latest news

博客园 - Hawk_Yuan

JQGrid自動翻頁 Aspose.Words aspose.cell C#通过SQL读写文件 asp.net mvc 4 json大数据异常 提示JSON字符长度超出限制的异常[转载] 日期转换成字符串 LinkServer GridView小记 SoapHeader Credential 等等等 决心要创业成功的10个必备信念 成功人的共性 会计科目 [转]BOM分层六项原则 [转]ERP核心理念讲座系列(四) [转]ERP核心理念讲座系列(三) [转]ERP核心理念讲座系列(二) [转]ERP核心理念讲座系列(一)
Aspose.Cells
Hawk_Yuan · 2021-05-04 · via 博客园 - Hawk_Yuan

#region 导入数据到变量dt
String AsposeLicPath = String.Empty;
if (System.Configuration.ConfigurationManager.AppSettings["AsposeLicPath"] == null)
throw new Exception("Please setup [AsposeLicPath] in Web.Config!");
else
AsposeLicPath = System.Configuration.ConfigurationManager.AppSettings["AsposeLicPath"];

Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(AsposeLicPath);
//打开文件,参数可以是文件的路径,也可以直接传入一个文件流
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(fileStream);
//获取sheet表
Aspose.Cells.WorksheetCollection worksheets = workbook.Worksheets;
Aspose.Cells.Worksheet worksheet = null;
Aspose.Cells.Cells cell = null;

//默认第一行为列名 所以第一行不读,索引从第二行开始
int rowIndex = 0;
//从第一列读取
int colIndex = 0;
worksheet = worksheets[0];
//获取每个sheet表的所有单元格
cell = worksheet.Cells;
for (int i = 0; i < cell.MaxDataColumn + 1; i++)
{
if (i < 2)
dt.Columns.Add(new DataColumn(cell[0, i].Value.ToString(), typeof(string)));
else
dt.Columns.Add(new DataColumn(cell[0, i].Value.ToString(), typeof(int)));
}
cell.ExportDataTable(dt, rowIndex + 1, colIndex, cell.MaxDataRow, false);

worksheets.Clear();
worksheet = null;
worksheets = null;
workbook = null;
#endregion

创建Excel档案

Aspose.Cells.Workbook workbook1 = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet sheet1 = workbook1.Worksheets[0];
Aspose.Cells.Cells cells1 = sheet1.Cells;

int Colnum = dtResult.Columns.Count;//表格列数
int Rownum = dtResult.Rows.Count;//表格行数
//生成行 列名行
for (int i = 0; i < Colnum; i++)
{
cells1[0, i].PutValue(dtResult.Columns[i].ColumnName);
}

//生成数据行
for (int i = 0; i < Rownum; i++)
{
for (int k = 0; k < Colnum; k++)
{
cells1[1 + i, k].PutValue(dtResult.Rows[i][k].ToString(), true);
Aspose.Cells.Style style = cells1[1 + i, k].GetStyle();
if ((k + 1) % 7 == 0)
style.Number = 2;
else
{
style.Number = 1;
}
style.Font.Size = 11;
cells1[1 + i, k].SetStyle(style);
}
}

设置样式

Aspose.Cells.Style style2 = cells1[0, i + 0].GetStyle();
style2.ForegroundColor = System.Drawing.Color.FromArgb(128, 96, 0);
style2.Pattern = Aspose.Cells.BackgroundType.Solid;
style2.Font.Size = 12;
style2.Font.IsBold = true;
style2.Font.Color = System.Drawing.Color.White;
cells1[0, i + 0].SetStyle(style2);
cells1[0, i + 1].SetStyle(style2);
cells1[0, i + 2].SetStyle(style2);
cells1[0, i + 3].SetStyle(style2);
cells1[0, i + 4].SetStyle(style2);
cells1[0, i + 5].SetStyle(style2);
cells1[0, i + 6].SetStyle(style2);

保存Excel档案

workbook1.Save(ConfigurationManager.AppSettings["TFile"].ToString());
workbook1.Worksheets.Clear();
sheet1 = null;
workbook1 = null;