在单元格中显示前导撇号
Contents
[
Hide
]
在Microsoft Excel中,单元格值的前导’是隐藏的。Aspose.Cells提供了默认显示撇号的功能。为此,API提供了Workbook.Settings.QuotePrefixToStyle 属性。此属性指示在输入以单引号开头的字符串值时是否设置 QuotePrefix 。将Workbook.Settings.QuotePrefixToStyle 属性设置为false 将在输出的excel文件中显示前导'。
以下屏幕截图显示了带有可见撇号的输出Excel文件。
以下代码片段演示了通过在源Excel文件中添加带有智能标记的数据来实现此目的。 源文件和输出文件已附上以供参考。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
Workbook workbook = new Workbook(sourceDir + "AllowLeadingApostropheSample.xlsx"); | |
workbook.Settings.QuotePrefixToStyle = false; | |
// Open a designer spreadsheet containing smart markers | |
designer.Workbook = workbook; | |
List<DataObject> list = new List<DataObject> | |
{ | |
new DataObject | |
{ | |
Id =1, | |
Name = "demo" | |
}, | |
new DataObject | |
{ | |
Id=2, | |
Name = "'demo" | |
} | |
}; | |
// Set the data source for the designer spreadsheet | |
designer.SetDataSource("sampleData", list); | |
// Process the smart markers | |
designer.Process(); | |
designer.Workbook.Save(outputDir + "AllowLeadingApostropheSample_out.xlsx"); |
DataObject类的实现如下
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
internal class DataObject | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} |