Mostra l apostrofo iniziale nelle celle

Mostra apostrofo iniziale nelle celle

In Microsoft Excel, l’apostrofo iniziale nel valore della cella è nascosto. Aspose.Cells fornisce la funzionalità per visualizzare l’apostrofo per impostazione predefinita. A tal fine, l’API fornisce la proprietà Workbook.Settings.QuotePrefixToStyle. Questa proprietà indica se impostare la proprietà QuotePrefix quando si inserisce un valore di stringa che inizia con un singolo apice nella cella. Impostando la proprietà Workbook.Settings.QuotePrefixToStyle su false si visualizzerà l’apostrofo iniziale nel file excel di output.

Lo screenshot seguente mostra il file excel di output con l’apostrofo visibile.

todo:image_alt_text

Il seguente snippet di codice dimostra ciò aggiungendo dati con Smart Markers nel file excel di origine. Sono allegati i file excel di origine e di output per riferimento.

File sorgente

File di output

Codice di Esempio

// 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");

L’implementazione della classe DataObject è riportata di seguito

// 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;
}
}