ODS Dosyalarında Arka Planla Çalışma
ODS Dosyalarında Arka Plan
Arka plan ODS dosyalarına eklenebilir. Arka plan ya renkli arka plan ya da grafik arka planı olabilir. Dosya açıkken arka plan görünmez ancak dosya PDF olarak yazdırılırsa, arka plan oluşturulan PDF’de görünür. Arka plan ayrıca yazdırma önizleme ile de görünür.
Aspose.Cells, ODS dosyalarında arka plan bilgilerini okuma ve arka plan ekleme yeteneği sağlar.
OSD dosyasından Arka Plan Bilgisi Oku
Aspose.Cells, ODS Dosyalarında arka planı yönetmek için ODSPageBackground sınıfını sağlar. Aşağıdaki kod örneği, ODSPageBackground sınıfının kullanımını göstererek kaynak ODS dosyasını yükler ve arka plan bilgilerini okur. Referans için lütfen kod tarafından oluşturulmuş Konsol Çıktısına bakın.
Örnek Kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
public static void main(String[] args) throws Exception { | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// The path to the output directory. | |
String outDir = Utils.Get_OutputDirectory(); | |
//Load source Excel file | |
Workbook workbook = new Workbook(sourceDir + "GraphicBackground.ods"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
OdsPageBackground background = worksheet.getPageSetup().getODSPageBackground(); | |
System.out.println("Background Type: " + getTypeValue(background.getType())); | |
System.out.println("Backgorund Position: " + getPositionValue(background.getGraphicPositionType())); | |
//Save background image | |
ByteArrayInputStream stream = new ByteArrayInputStream(background.getGraphicData()); | |
BufferedImage image = ImageIO.read(stream); | |
ImageIO.write(image, "png", new File(outDir + "background.png")); | |
System.out.println("ReadODSBackground executed successfully."); | |
} | |
public static String getTypeValue(int type) { | |
String value = ""; | |
if(type == OdsPageBackgroundType.COLOR) { | |
value = "COLOR"; | |
} else if(type == OdsPageBackgroundType.GRAPHIC) { | |
value = "GRAPHIC"; | |
} else if(type == OdsPageBackgroundType.NONE) { | |
value = "NONE"; | |
} | |
return value; | |
} | |
public static String getPositionValue(int position) { | |
String value = ""; | |
if(position == OdsPageBackgroundGraphicPositionType.BOTTOM_CENTER) { | |
value = "BOTTOM_CENTER"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.BOTTOM_LEFT) { | |
value = "BOTTOM_LEFT"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.BOTTOM_RIGHT) { | |
value = "BOTTOM_RIGHT"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.CENTER_CENTER) { | |
value = "CENTER_CENTER"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.CENTER_LEFT) { | |
value = "CENTER_LEFT"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.CENTER_RIGHT) { | |
value = "CENTER_RIGHT"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.TOP_CENTER) { | |
value = "TOP_CENTER"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.TOP_LEFT) { | |
value = "TOP_LEFT"; | |
} else if(position == OdsPageBackgroundGraphicPositionType.TOP_RIGHT) { | |
value = "TOP_RIGHT"; | |
} | |
return value; | |
} |
Konsol Çıktısı
Background Type: GRAPHIC
Backgorund Position: CENTER_CENTER
ODS dosyasına Renkli Arka Plan Ekleme
Aspose.Cells, ODSPageBackground sınıfını kullanarak ODS dosyalarında arka planı yönetir. Aşağıdaki kod örneği, ODSPageBackground.Color özelliğinin kullanımını göstererek renkli arka planı ODS dosyasına ekler. Referans için lütfen kod tarafından oluşturulmuş çıktı ODS dosyasına bakın.
Örnek Kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the output directory. | |
String outDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
worksheet.getCells().get(0, 0).setValue(1); | |
worksheet.getCells().get(1, 0).setValue(2); | |
worksheet.getCells().get(2, 0).setValue(3); | |
worksheet.getCells().get(3, 0).setValue(4); | |
worksheet.getCells().get(4, 0).setValue(5); | |
worksheet.getCells().get(5, 0).setValue(6); | |
worksheet.getCells().get(0, 1).setValue(7); | |
worksheet.getCells().get(1, 1).setValue(8); | |
worksheet.getCells().get(2, 1).setValue(9); | |
worksheet.getCells().get(3, 1).setValue(10); | |
worksheet.getCells().get(4, 1).setValue(11); | |
worksheet.getCells().get(5, 1).setValue(12); | |
OdsPageBackground background = worksheet.getPageSetup().getODSPageBackground(); | |
background.setColor(Color.getAzure()); | |
background.setType(OdsPageBackgroundType.COLOR); | |
workbook.save(outDir + "ColoredBackground.ods", SaveFormat.ODS); |
ODS dosyasına Grafik Arka Plan Ekleme
Aspose.Cells, ODSPageBackground sınıfını kullanarak ODS dosyalarında arka planı yönetir. Aşağıdaki kod örneği, ODSPageBackground.GraphicData özelliğinin kullanımını göstererek grafik arka planı ODS dosyasına ekler. Referans için lütfen kod tarafından oluşturulmuş çıktı ODS dosyasına bakın.
Örnek Kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// The path to the output directory. | |
String outDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
worksheet.getCells().get(0, 0).setValue(1); | |
worksheet.getCells().get(1, 0).setValue(2); | |
worksheet.getCells().get(2, 0).setValue(3); | |
worksheet.getCells().get(3, 0).setValue(4); | |
worksheet.getCells().get(4, 0).setValue(5); | |
worksheet.getCells().get(5, 0).setValue(6); | |
worksheet.getCells().get(0, 1).setValue(7); | |
worksheet.getCells().get(1, 1).setValue(8); | |
worksheet.getCells().get(2, 1).setValue(9); | |
worksheet.getCells().get(3, 1).setValue(10); | |
worksheet.getCells().get(4, 1).setValue(11); | |
worksheet.getCells().get(5, 1).setValue(12); | |
OdsPageBackground background = worksheet.getPageSetup().getODSPageBackground(); | |
BufferedImage image = ImageIO.read(new File(sourceDir + "background.png")); | |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
ImageIO.write(image, "png", bos ); | |
byte [] imageData = bos.toByteArray(); | |
background.setType(OdsPageBackgroundType.GRAPHIC); | |
background.setGraphicData(imageData); | |
background.setGraphicType(OdsPageBackgroundGraphicType.AREA); | |
workbook.save(outDir + "GraphicBackground.ods", SaveFormat.ODS); |