Travailler avec l arrière plan dans les fichiers ODS
Arrière-plan dans les fichiers ODS
Un arrière-plan peut être ajouté aux feuilles dans les fichiers ODS. L’arrière-plan peut être soit un arrière-plan coloré, soit un arrière-plan graphique. L’arrière-plan n’est pas visible lorsque le fichier est ouvert, mais s’il est imprimé en PDF, l’arrière-plan est visible dans le PDF généré. L’arrière-plan est également visible dans la boîte de dialogue d’aperçu avant impression.
Aspose.Cells permet de lire les informations d’arrière-plan et d’ajouter l’arrière-plan dans les fichiers ODS.
Lire les informations d’arrière-plan à partir du fichier ODS
Aspose.Cells fournit la classe OdsPageBackground pour gérer l’arrière-plan dans les fichiers ODS. L’exemple de code suivant démontre l’utilisation de la classe OdsPageBackground en chargeant le fichier ODS source et en lisant les informations d’arrière-plan. Veuillez consulter la sortie Console générée par le code pour référence.
Code d’exemple
// 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"); |
Sortie console
Background Type: Graphic
Backgorund Position: CenterCenter
Ajouter un arrière-plan coloré au fichier ODS
Aspose.Cells fournit la classe OdsPageBackground pour gérer l’arrière-plan dans les fichiers ODS. L’exemple de code suivant montre l’utilisation de la propriété OdsPageBackground.Color pour ajouter un arrière-plan coloré au fichier ODS. Veuillez consulter le fichier ODS généré par le code pour référence.
Code d’exemple
// 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); |
Ajouter un arrière-plan graphique au fichier ODS
Aspose.Cells fournit la classe OdsPageBackground pour gérer l’arrière-plan dans les fichiers ODS. L’exemple de code suivant montre l’utilisation de la propriété OdsPageBackground.GraphicData pour ajouter un arrière-plan graphique au fichier ODS. Veuillez consulter le fichier ODS généré par le code pour référence.
Code d’exemple
// 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); |