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

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
N
Netflix TechBlog - Medium
P
Privacy International News Feed
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
C
Cybersecurity and Infrastructure Security Agency CISA
The Register - Security
The Register - Security
P
Palo Alto Networks Blog
GbyAI
GbyAI
量子位
Simon Willison's Weblog
Simon Willison's Weblog
Cyberwarzone
Cyberwarzone
M
MIT News - Artificial intelligence
T
Threatpost
腾讯CDC
MyScale Blog
MyScale Blog
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
博客园 - 叶小钗
V
V2EX
美团技术团队
NISL@THU
NISL@THU
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
C
Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
爱范儿
爱范儿
G
Google Developers Blog
博客园 - Franky
P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
B
Blog
Spread Privacy
Spread Privacy
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Latest news
Latest news
The GitHub Blog
The GitHub Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
F
Full Disclosure
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
Scott Helme
Scott Helme
C
CERT Recently Published Vulnerability Notes
Jina AI
Jina AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs

博客园 - Yu

Illegal characters in path 依赖注入的 Singleton、Scoped、Transient vs2015 编译报错:The project references NuGet package(s) that are missing on this computer... discuz 迁移 uc_server 报错 The timeout period elapsed prior to completion of the operation or the server is not responding. 微信小程序笔记 xmlns 与 targetNamespace 的解释 Ubuntu64 apache2+lvs+Keepalived mysql --initialize specified but the data directory has files in it select2 多选设置默认值 VS 2015 IDE 不支持 MS SQL 2000 生成 dbml Ajax 如何执行 Response.Redirect ng 发生 Error: ELOOP: too many symbolic links encountered... jquery call cross-domain webapi owin self-host HtmlAgilityPack 使用 微信 oauth2 两次回调 EF 热加载 Winform/Asp.net vs2015 使用 Eazfuscator.NET 3.3 The requested page cannot be accessed because the related configuration data for the page is invalid.
NPOI CellStyle 设置
Yu · 2018-01-31 · via 博客园 - Yu
    public class ExcelNPOIUnit
    {
        public static void SetCell(IWorkbook workbook, ISheet sheet,
             IRow row, int createCellIndex, object cellContent, CellType cellType, HorizontalAlignment alignment)
        {
            IDataFormat celldataformat = workbook.CreateDataFormat();
            IFont font = workbook.CreateFont();
            font.FontName = "Calibri";

            ICell cell = row.FirstOrDefault(n => n.ColumnIndex == createCellIndex);
            if (cell == null)
                cell = row.CreateCell(createCellIndex);

            cell.CellStyle.SetFont(font);
            cell.CellStyle.BorderLeft = BorderStyle.Thin;
            cell.CellStyle.BorderRight = BorderStyle.Thin;
            cell.CellStyle.BorderTop = BorderStyle.Thin;
            cell.CellStyle.BorderBottom = BorderStyle.Thin;

            //在这里设置会影响全部单元格
            //cell.CellStyle.Alignment = alignment;

            double tmp = -1;
            if (cellType == CellType.Numeric && double.TryParse(cellContent.ToString(), out tmp))
            {
                //必须在这里这样设置,才能对当前单元格有效
                ICellStyle cellstyle = workbook.CreateCellStyle();
                cellstyle.CloneStyleFrom(cell.CellStyle);
                cellstyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0");
                cellstyle.Alignment = alignment;
                cell.CellStyle = cellstyle;

                cell.SetCellValue(tmp);
            }
            else
            {
                //必须在这里这样设置,才能对当前单元格有效
                ICellStyle cellstyle = workbook.CreateCellStyle();
                cellstyle.CloneStyleFrom(cell.CellStyle);
                cellstyle.Alignment = alignment;
                cell.CellStyle = cellstyle;
                cell.SetCellValue(cellContent.ToString());
            }
        }

        public static void SaveSheet(string fullname, ISheet sheet)
        {
            using (FileStream writefile = new FileStream(fullname, FileMode.Create, FileAccess.Write))
            {
                sheet.Workbook.Write(writefile);
            }
        }
        public static IWorkbook GetWorkbook(string fullname)
        {
            IWorkbook workbook = null;

            if (fullname.ToLower().EndsWith(".xls"))
            {
                using (FileStream fs = new FileStream(fullname, FileMode.Open, FileAccess.Read))
                {
                    workbook = new HSSFWorkbook(fs);
                }
            }
            else
            {
                using (FileStream fs = new FileStream(fullname, FileMode.Open, FileAccess.Read))
                {
                    workbook = new XSSFWorkbook(fs);
                }
            }

            return workbook;
        }

    }

var wk = ExcelNPOIUnit.GetWorkbook(logname);

var sheet = wk.GetSheet("Sheet1");

int rowindex = 2;
int cellindex = 0;
foreach (var item in list)
{
IRow row = sheet.CreateRow(rowindex);

ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.CreateDate, CellType.String, HorizontalAlignment.Center);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.TotalFilesReceived, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.TotalPagesReceived, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.ShippedFiles, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.ShippedPages, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.PendingFiles, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.PendingPages, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.NofFiles_Priority, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.NoofPgs_Priority, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.NoofFiles_NoPriority, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.NoofPgs_NoPriority, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.NoofFiles_Today, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.NoofPgs_Today, CellType.Numeric, HorizontalAlignment.Right);
ExcelNPOIUnit.SetCell(wk, sheet, row, cellindex++, item.Remarks, CellType.Numeric, HorizontalAlignment.Left);
rowindex++;
cellindex = 0;
}

ExcelNPOIUnit.SaveSheet(logname, sheet);