Estrai dati del tema dai file Excel
Aspose.Cells consente agli utenti di estrarre dati correlati al tema dal file Excel. Ad esempio, è possibile estrarre il nome del tema applicato al foglio di lavoro e il colore del tema applicato alla cella o ai bordi della cella, ecc.
Puoi applicare un tema al tuo foglio di lavoro usando Microsoft Excel tramite il comando Layout Pagina > Temi.
Codice C# per estrarre i dati del tema dal file Excel
Il seguente codice di esempio estrae il nome del Tema applicato al foglio di lavoro di origine e quindi estrae il colore del Tema applicato alla cella A1 e il colore del Tema applicato al bordo inferiore della cella.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Extract theme name applied to this workbook | |
Console.WriteLine(workbook.Theme); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cell A1 | |
Cell cell = worksheet.Cells["A1"]; | |
// Get the style object | |
Style style = cell.GetStyle(); | |
if (style.ForegroundThemeColor != null) | |
{ | |
// Extract theme color applied to this cell if theme has foregroundtheme color defined | |
Console.WriteLine(style.ForegroundThemeColor.ColorType); | |
} | |
else | |
{ | |
Console.WriteLine("Theme has not foreground color defined."); | |
} | |
// Extract theme color applied to the bottom border of the cell if theme has border color defined | |
Border bot = style.Borders[BorderType.BottomBorder]; | |
if (bot.ThemeColor != null) | |
{ | |
Console.WriteLine(bot.ThemeColor.ColorType); | |
} | |
else | |
{ | |
Console.WriteLine("Theme has not Border color defined."); | |
} |