Style.Custom Özelliğini Ayarlarken Özel Sayı Formatını Kontrol Edin
Contents
[
Hide
]
Olası Kullanım Senaryoları
için geçersiz özel sayı biçimi atarsanızStil. Özelözelliğinden sonra Aspose.Cells herhangi bir istisna atmaz. Ancak, Aspose.Cells’in atanan özel numara biçiminin geçerli olup olmadığını kontrol etmesini istiyorsanız, lütfenWorkbook.Settings.CheckCustomNumberFormat mülkiyetdoğru.
Style.Custom özelliğini ayarlarken Özel Sayı Formatını kontrol edin
Aşağıdaki örnek kod, geçersiz bir özel sayı biçimi atar.Stil. Özel Emlak. zaten ayarladığımız içinWorkbook.Settings.CheckCustomNumberFormat mülkiyetdoğru , bu nedenle API örneğin CellsException’ı atarGeçersiz sayı biçimi.
Basit kod
This file contains hidden or 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 | |
// Create a workbook | |
Workbook wb = new Workbook(); | |
// Setting this property to true will make Aspose.Cells to throw exception | |
// when invalid custom number format is assigned to Style.Custom property | |
wb.getSettings().setCheckCustomNumberFormat(true); | |
// Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access cell A1 and put some number inside it | |
Cell c = ws.getCells().get("A1"); | |
c.putValue(2347); | |
// Access cell's style and set its Style.Custom property | |
Style s = c.getStyle(); | |
try { | |
// This line will throw exception if | |
// Workbook.Settings.CheckCustomNumberFormat is set to true | |
s.setCustom("ggg @ fff"); // Invalid custom number format | |
c.setStyle(s); | |
} | |
catch (Exception ex) { | |
System.out.println("Exception Occured"); | |
} | |
System.out.println("Done"); |