使用 ODS 文件中的背景
Contents
[
Hide
]
ODS 文件中的背景
背景可以添加到 ODS 文件中的工作表。背景可以是彩色背景或图形背景。文件打开时背景不可见,但如果文件打印为 PDF,则背景在生成的 PDF 中可见。背景在打印预览对话框中也可见。
Aspose.Cells 提供读取背景信息的能力,在ODS文件中添加背景。
从 ODS 文件中读取背景信息
Aspose.Cells 提供了Ods页面背景类来管理 ODS 文件中的背景。下面的代码示例演示了使用Ods页面背景通过加载类来源 ODS文件并阅读背景信息。请参阅代码生成的控制台输出以供参考。
示例代码
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 | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
//Load source Excel file | |
Workbook workbook = new Workbook(sourceDir + "GraphicBackground.ods"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
OdsPageBackground background = worksheet.PageSetup.ODSPageBackground; | |
Console.WriteLine("Background Type: " + background.Type.ToString()); | |
Console.WriteLine("Backgorund Position: " + background.GraphicPositionType.ToString()); | |
//Save background image | |
Bitmap image = new Bitmap(new MemoryStream(background.GraphicData)); | |
image.Save(outputDir + "background.jpg"); |
控制台输出
背景类型:图形
背景位置:CenterCenter
将彩色背景添加到 ODS 文件
Aspose.Cells 提供了Ods页面背景类来管理 ODS 文件中的背景。下面的代码示例演示了使用OdsPageBackground.Color属性将颜色背景添加到 ODS 文件。请参阅输出 ODS代码生成的文件供参考。
示例代码
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 | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells[0, 0].Value = 1; | |
worksheet.Cells[1, 0].Value = 2; | |
worksheet.Cells[2, 0].Value = 3; | |
worksheet.Cells[3, 0].Value = 4; | |
worksheet.Cells[4, 0].Value = 5; | |
worksheet.Cells[5, 0].Value = 6; | |
worksheet.Cells[0, 1].Value = 7; | |
worksheet.Cells[1, 1].Value = 8; | |
worksheet.Cells[2, 1].Value = 9; | |
worksheet.Cells[3, 1].Value = 10; | |
worksheet.Cells[4, 1].Value = 11; | |
worksheet.Cells[5, 1].Value = 12; | |
OdsPageBackground background = worksheet.PageSetup.ODSPageBackground; | |
background.Color = Color.Azure; | |
background.Type = OdsPageBackgroundType.Color; | |
workbook.Save(outputDir + "ColoredBackground.ods", SaveFormat.Ods); |
将图形背景添加到 ODS 文件
Aspose.Cells 提供了Ods页面背景类来管理 ODS 文件中的背景。下面的代码示例演示了使用OdsPageBackground.GraphicData属性将图形背景添加到 ODS 文件。请参阅输出 ODS代码生成的文件供参考。
示例代码
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 | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells[0, 0].Value = 1; | |
worksheet.Cells[1, 0].Value = 2; | |
worksheet.Cells[2, 0].Value = 3; | |
worksheet.Cells[3, 0].Value = 4; | |
worksheet.Cells[4, 0].Value = 5; | |
worksheet.Cells[5, 0].Value = 6; | |
worksheet.Cells[0, 1].Value = 7; | |
worksheet.Cells[1, 1].Value = 8; | |
worksheet.Cells[2, 1].Value = 9; | |
worksheet.Cells[3, 1].Value = 10; | |
worksheet.Cells[4, 1].Value = 11; | |
worksheet.Cells[5, 1].Value = 12; | |
OdsPageBackground background = worksheet.PageSetup.ODSPageBackground; | |
background.Type = OdsPageBackgroundType.Graphic; | |
background.GraphicData = File.ReadAllBytes(sourceDir + "background.jpg"); | |
background.GraphicType = OdsPageBackgroundGraphicType.Area; | |
workbook.Save(outputDir + "GraphicBackground.ods", SaveFormat.Ods); |