Lavorare con lo sfondo nei file ODS
Sfondo nei file ODS
Lo sfondo può essere aggiunto ai fogli dei file ODS. Lo sfondo può essere di colore o grafico. Lo sfondo non è visibile quando il file è aperto ma se il file viene stampato come PDF, lo sfondo è visibile nel PDF generato. Lo sfondo è anche visibile nella visualizzazione anteprima di stampa.
Aspose.Cells fornisce la capacità di leggere le informazioni di sfondo e aggiungere lo sfondo nei file ODS.
Leggi informazioni di sfondo dal file ODS
Aspose.Cells fornisce la classe OdsPageBackground per gestire lo sfondo nei file ODS. Il seguente esempio di codice dimostra l’uso della classe OdsPageBackground caricando il file ODS di origine e leggendo le informazioni di sfondo. Si prega di consultare l’output della Console generato dal codice per riferimento.
Codice di Esempio
// 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"); |
Output della console
Background Type: Graphic
Backgorund Position: CenterCenter
Aggiungere uno sfondo colorato al file ODS
Aspose.Cells fornisce la classe OdsPageBackground per gestire lo sfondo nei file ODS. Il seguente esempio di codice dimostra l’uso della proprietà OdsPageBackground.Color per aggiungere uno sfondo di colore al file ODS. Si prega di consultare il file ODS di output generato dal codice per riferimento.
Codice di Esempio
// 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); |
Aggiungere uno sfondo grafico al file ODS
Aspose.Cells fornisce la classe OdsPageBackground per gestire lo sfondo nei file ODS. Il seguente esempio di codice dimostra l’uso della proprietà OdsPageBackground.GraphicData per aggiungere uno sfondo grafico al file ODS. Si prega di consultare il file ODS di output generato dal codice per riferimento.
Codice di Esempio
// 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); |