Open XML SDK:格式化 Excel 单元格的一部分
将 Open XML for Excel 与 DocumentFormat.OpenXml.Spreadsheet
结合使用,如何仅将部分文本设置为粗体?
var cell = new Cell {
//DataType = CellValues.InlineString,
CellReference = "A" + 1
};
// TODO: Set "bold text" to bold style
//var inlineString = new InlineString();
//inlineString.AppendChild(new Text { Text = "Normal text... bold text..." });
//cell.AppendChild(inlineString);
注释掉现在使用的代码,但应该或也许应该更改。
Using Open XML for Excel with DocumentFormat.OpenXml.Spreadsheet
, how do I set only part of a text to bold?
var cell = new Cell {
//DataType = CellValues.InlineString,
CellReference = "A" + 1
};
// TODO: Set "bold text" to bold style
//var inlineString = new InlineString();
//inlineString.AppendChild(new Text { Text = "Normal text... bold text..." });
//cell.AppendChild(inlineString);
Commented out code that's used now, but should or maybe should be changed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要仅将部分文本设置为粗体,您需要通过将文本插入
SharedStringTable
并将单元格的数据类型设置为SharedString
而不是InlineString 来控制它
。这将使 CellValue 成为该表的引用,如 0、1、2 等,并允许比执行内联字符串进行更多控制。以下是一些示例代码,介绍如何将短语“普通文本...粗体文本...”的第二部分设置为粗体:
要使用此方法,您需要首先找到 SharedStringTable 的实例然后将新的
ShareStringItem
插入其中:To only set part of the text to bold you will want to control that by inserting your text into the
SharedStringTable
and making your cell's data type beSharedString
and notInlineString
. This will make the CellValue be a reference into this table, like 0, 1, 2, etc. and allow more control then doing an inline string.Here is some sample code on how to make the second part of the pharse "Normal text... bold text..." bold:
To use this method you want to first find an instance of the
SharedStringTable
and then insert your newShareStringItem
into it: