Extrahera temadata från Excel-fil
Contents
[
Hide
]
Aspose.Cells låter användarna extrahera temarelaterade data från Excel-fil. Till exempel kan du extrahera Temanamn som tillämpas på arbetsbok och Temafärg som tillämpas på cell eller cellens kanter, etc.
Du kan tillämpa tema på din arbetsbok med Microsoft Excel via kommandot Sidlayout > Teman.
C# kod för att extrahera temadata från Excel-fil
Följande exempelkod extraherar temanamnet som tillämpas på källarbetsboken och extraherar sedan temafärgen som tillämpas på cell A1 och temafärgen som tillämpas på cellens nedre kant.
This file contains 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-.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."); | |
} |