从 Excel 文件中提取主题数据
Contents
[
Hide
]
Aspose.Cells 允许用户从 Excel 文件中提取主题相关数据。例如,您可以提取应用于工作簿的主题名称和应用于单元格或单元格边框的主题颜色等。
您可以使用 Microsoft Excel 通过页面布局 > 主题命令将主题应用到您的工作簿。
C# 从 Excel 文件中提取主题数据的代码
以下示例代码提取应用于源工作簿的主题名称,然后提取应用于单元格 A1 的主题颜色和应用于单元格底部边框的主题颜色。
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."); | |
} |