Hitta celler med specifik stil
Använder Microsoft Excel
Det här är stegen som krävs för att söka i celler med specifika stilar i MS Excel.
- VäljHitta och välj iFliken Hem.
- VäljHitta.
- Klickalternativom avancerade alternativ inte är synliga.
- VäljVälj format från Cell… frånFormatera falla ner.
- Markera cellen med stilen som du vill söka efter.
- KlickHitta alla för att hitta alla celler med stil som liknar din valda cell.
Använder Aspose.Cells for Java
Aspose.Cells for Java tillhandahåller funktionen för att hitta celler i kalkylblad med någon specifik stil. För detta tillhandahåller APIFindOptions.setStyle() fast egendom.
Exempelkod
Följande kodavsnitt hittar alla celler som har samma stil som cellenA1 och ändrar texten i dessa celler. Se skärmdumpen av käll- och utdatafilerna för att analysera utdata från exempelkoden.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FindCellsWithSpecificStyle.class); | |
Workbook workbook = new Workbook(dataDir + "TestBook.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the style of cell A1 | |
Style style = worksheet.getCells().get("A1").getStyle(); | |
// Specify the style for searching | |
FindOptions options = new FindOptions(); | |
options.setStyle(style); | |
Cell nextCell = null; | |
do { | |
// Find the cell that has a style of cell A1 | |
nextCell = worksheet.getCells().find(null, nextCell, options); | |
if (nextCell == null) | |
break; | |
// Change the text of the cell | |
nextCell.putValue("Found"); | |
} while (true); | |
workbook.save(dataDir + "out.xlsx"); |
Efter exekvering av kod kommer alla celler som har samma stil som cell A1 att ha texten “Found”.
Skärmdumpar
Figur: Källfil med celler som har stilar
Här är utdatafilen som genereras av följande kod. Du kan se alla celler som har samma stil som cellenA1 har texten “Found”
Figur:Utdatafil med hittade celler efter sökning efterA1 stil