在单元格中显示前导撇号
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-Java | |
//directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
Workbook workbook = new Workbook(sourceDir + "AllowLeadingApostropheSample.xlsx"); | |
workbook.getSettings().setQuotePrefixToStyle(false); | |
// Open a designer spreadsheet containing smart markers | |
designer.setWorkbook(workbook); | |
ArrayList<DataObject> list = new ArrayList<>(); | |
list.add(new DataObject(1, "demo")); | |
list.add(new DataObject(2, "'demo")); | |
// Set the data source for the designer spreadsheet | |
designer.setDataSource("sampleData", list); | |
// Process the smart markers | |
designer.process(); | |
designer.getWorkbook().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-Java | |
public class DataObject | |
{ | |
private int id; | |
private String name; | |
public DataObject(int id, String name) | |
{ | |
this.id = id; | |
this.name = name; | |
} | |
public int getId() | |
{ | |
return this.id; | |
} | |
public void setId(int value) | |
{ | |
this.id = value; | |
} | |
public String getName() | |
{ | |
return this.name; | |
} | |
public void setName(String value) | |
{ | |
this.name = value; | |
} | |
} |