ODS ファイルの背景の操作
Contents
[
Hide
]
ODS ファイルの背景
背景は、ODS ファイルのシートに追加できます。背景は、色付きの背景またはグラフィックの背景のいずれかです。ファイルが開いているときは背景は表示されませんが、ファイルが PDF として印刷される場合、背景は生成された PDF で表示されます。背景は印刷プレビュー ダイアログでも表示されます。
Aspose.Cells は、背景情報を読み取り、ODS ファイルに背景を追加する機能を提供します。
ODS ファイルから背景情報を読み取る
Aspose.Cells はOdsPageBackground ODS ファイルの背景を管理するクラス。次のコード サンプルは、OdsPageBackgroundクラスをロードしてソース 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 はOdsPageBackgroundODS ファイルの背景を管理するクラス。次のコード サンプルは、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 はOdsPageBackgroundODS ファイルの背景を管理するクラス。次のコード サンプルは、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); |