Hitta celler med specifik stil
Använda Microsoft Excel
Dessa är stegen som krävs för att söka celler med specifika stilar i MS Excel.
- Välj Sök & Markera i Startfliken.
- Välj Hitta.
- Klicka på Alternativ om avancerade alternativ inte är synliga.
- Välj Välj format från cell… från rullgardinsmenyn Format.
- Välj cellen med den stil som du vill söka efter.
- Klicka på Hitta alla för att hitta alla celler med stil liknande din valda cell.
Använda Aspose.Cells for Java
Aspose.Cells for Java tillhandahåller funktionen att hitta celler i arbetsblad med en viss stil. För detta tillhandahåller API:et egenskapen FindOptions.setStyle().
Exempelkod
Följande kodsnutt hittar alla celler som har samma stil som cellen A1 och ändrar texten i dessa celler. Se gärna skärmbilden av käll- och utdatafilerna för att analysera utdata av 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 att koden har utförts kommer alla celler som har samma stil som cell A1 att ha texten “Hittad”.
Skärmbilder
Figur: Källfil med celler som har stilar
Här är utdatafilen som genererats av följande kod. Du kan se att alla celler som har samma stil som cellen A1 har texten “Hittad”
Figur: Utdatafil med hittade celler efter sökning med stil A1