zoukankan      html  css  js  c++  java
  • OpenXML 设置Excel的单元格字体加粗

    在网上查资料搜索到别人的解决方案,如果想整个Excel都加粗,那么直接用下面的代码就可以

    Bold bold=new Bold();

    但是如果是设定一些特殊的单元格加粗,那么只需要用以下的代码就可以了

    using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filename, true))
    {
        WorkbookPart workBookPart = spreadsheetDocument.WorkbookPart;
    
        WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
        WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
        SheetData sheetData = worksheetPart.Worksheet.Elements<SheetData>().First();
    
        //create a row
        Row row1 = new Row() { RowIndex = 1U };
    
        //create a new inline string cell
        Cell cell = new Cell() { CellReference = "A1" };
        cell.DataType = CellValues.InlineString;
    
        //create a run for the bold text
        Run run1 = new Run();
        run1.Append(new Text("ABC"));
        //create runproperties and append a "Bold" to them
        RunProperties run1Properties = new RunProperties();
        run1Properties.Append(new Bold());
        //set the first runs RunProperties to the RunProperties containing the bold
        run1.RunProperties = run1Properties;
    
        //create a second run for the non-bod text
        Run run2 = new Run();
        run2.Append(new Text(Environment.NewLine + "XYZ") { Space = SpaceProcessingModeValues.Preserve });
    
        //create a new inline string and append both runs
        InlineString inlineString = new InlineString();
        inlineString.Append(run1);
        inlineString.Append(run2);
    
        //append the inlineString to the cell.
        cell.Append(inlineString);
    
        //append the cell to the row
        row1.Append(cell);
    
        sheetData.Append(row1);
    }
  • 相关阅读:
    在CentOS-6.3环境下,利用grub工具手工制作Linux U盘安装盘
    Windowns DOS For 循环实例
    Bootstrap 标签的变体 实例样式
    Bootstrap两端对齐的导航实例
    bootstrap 分页样式代码
    C# 微信扫码支付API (微信扫码支付模式二)
    AjaxFileUpload 在C#中应用
    关于百度编辑器UEditor(1.4.3)在C#.NET中的应用实例
    电脑运行状态
    网络测试
  • 原文地址:https://www.cnblogs.com/yinxuejunfeng/p/14529333.html
Copyright © 2011-2022 走看看