Last active
November 16, 2022 10:57
-
-
Save aspose-com-gists/439a68a5e4305388c50ca306ef238de5 to your computer and use it in GitHub Desktop.
This Gist contains code snippets from examples of Aspose.Cells for Java.
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
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
This Gist contains code snippets from examples of Aspose.Cells for Java. |
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
Workbook workbook = new Workbook("SourceExcel.xls"); | |
workbook.save("outputExcel.xlsx", SaveFormat.XLSX); |
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-Java | |
// The path to the output directory. | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Adding sample values to cells | |
worksheet.getCells().get("A2").putValue("Category1"); | |
worksheet.getCells().get("A3").putValue("Category2"); | |
worksheet.getCells().get("A4").putValue("Category3"); | |
worksheet.getCells().get("B1").putValue("Column1"); | |
worksheet.getCells().get("B2").putValue(4); | |
worksheet.getCells().get("B3").putValue(20); | |
worksheet.getCells().get("B4").putValue(50); | |
worksheet.getCells().get("C1").putValue("Column2"); | |
worksheet.getCells().get("C2").putValue(50); | |
worksheet.getCells().get("C3").putValue(100); | |
worksheet.getCells().get("C4").putValue(150); | |
// Adding a chart to the worksheet | |
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN, 5, 0, 15, 5); | |
// Accessing the instance of the newly added chart | |
Chart chart = worksheet.getCharts().get(chartIndex); | |
// Setting chart data source as the range "A1:C4" | |
chart.setChartDataRange("A1:C4", true); | |
workbook.save( "ColumnChart.xlsx", SaveFormat.XLSX); |
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-Java | |
// The path to the output directory. | |
String sourceDir = Utils.Get_SourceDirectory();Workbook workbook = new Workbook(sourceDir + "GetTextWidthSample.xlsx"); | |
System.out.println("Text width: " + CellsHelper.getTextWidth(workbook.getWorksheets().get(0).getCells().get("A1").getStringValue(), workbook.getDefaultStyle().getFont(), 1)); |
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-Java | |
//Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
//Output directory | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(sourceDir + "SampleChangeTickLabelDirection.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Load the chart from source worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
chart.getCategoryAxis().getTickLabels().setDirectionType(ChartTextDirectionType.HORIZONTAL); | |
// Output the file | |
workbook.save(outputDir + "outputChangeTickLabelDirection.xlsx"); |
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-Java | |
// Instantiate a workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Set columns title | |
worksheet.getCells().get(0, 0).setValue("X"); | |
worksheet.getCells().get(0, 1).setValue("Y"); | |
// Create random data and save in the cells | |
for (int i = 1; i < 21; i++) | |
{ | |
worksheet.getCells().get(i, 0).setValue(i); | |
worksheet.getCells().get(i, 1).setValue(0.8); | |
} | |
for (int i = 21; i < 41; i++) | |
{ | |
worksheet.getCells().get(i, 0).setValue(i - 20); | |
worksheet.getCells().get(i, 1).setValue(0.9); | |
} | |
// Add a chart to the worksheet | |
int idx = worksheet.getCharts().add(ChartType.LINE_WITH_DATA_MARKERS, 1, 3, 20, 20); | |
// Access the newly created chart | |
Chart chart = worksheet.getCharts().get(idx); | |
// Set chart style | |
chart.setStyle(3); | |
// Set autoscaling value to true | |
chart.setAutoScaling(true); | |
// Set foreground color white | |
chart.getPlotArea().getArea().setForegroundColor(Color.getWhite()); | |
// Set Properties of chart title | |
chart.getTitle().setText("Sample Chart"); | |
// Set chart type | |
chart.setType(ChartType.LINE_WITH_DATA_MARKERS); | |
// Set Properties of categoryaxis title | |
chart.getCategoryAxis().getTitle().setText("Units"); | |
//Set Properties of nseries | |
int s2_idx = chart.getNSeries().add("A2: A2", true); | |
int s3_idx = chart.getNSeries().add("A22: A22", true); | |
// Set IsColorVaried to true for varied points color | |
chart.getNSeries().setColorVaried(true); | |
// Set properties of background area and series markers | |
chart.getNSeries().get(s2_idx).getArea().setFormatting(FormattingType.CUSTOM); | |
chart.getNSeries().get(s2_idx).getMarker().getArea().setForegroundColor(Color.getYellow()); | |
chart.getNSeries().get(s2_idx).getMarker().getBorder().setVisible(false); | |
// Set X and Y values of series chart | |
chart.getNSeries().get(s2_idx).setXValues("A2: A21"); | |
chart.getNSeries().get(s2_idx).setValues("B2: B21"); | |
// Set properties of background area and series markers | |
chart.getNSeries().get(s3_idx).getArea().setFormatting(FormattingType.CUSTOM); | |
chart.getNSeries().get(s3_idx).getMarker().getArea().setForegroundColor(Color.getGreen()); | |
chart.getNSeries().get(s3_idx).getMarker().getBorder().setVisible(false); | |
// Set X and Y values of series chart | |
chart.getNSeries().get(s3_idx).setXValues("A22: A41"); | |
chart.getNSeries().get(s3_idx).setValues("B22: B41"); | |
// Save the workbook | |
workbook.save(outDir + "LineWithDataMarkerChart.xlsx", SaveFormat.XLSX); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(GetChartSubTitleForODSFile.class) + "Charts/"; | |
String filePath = dataDir + "SampleChart.ods"; | |
Workbook workbook = new Workbook(filePath); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Load the chart from source worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
System.out.println("Chart Subtitle: " + chart.getSubTitle().getText()); |
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-Java | |
// directories | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a chart to the worksheet | |
int index = workbook.getWorksheets().add(SheetType.CHART); | |
Worksheet sheet = workbook.getWorksheets().get(index); | |
sheet.getCharts().addFloatingChart(ChartType.COLUMN, 0, 0, 1024, 960); | |
sheet.getCharts().get(0).getNSeries().add("{1,2,3}", false); | |
// Add checkbox to the chart. | |
sheet.getCharts().get(0).getShapes().addShapeInChart(MsoDrawingType.CHECK_BOX, PlacementType.MOVE, 400, 400, 1000, 600); | |
sheet.getCharts().get(0).getShapes().get(0).setText("CheckBox 1"); | |
// Convert chart to image with additional settings | |
workbook.save(outputDir + "InsertCheckboxInChartSheet_out.xlsx"); |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "ValidationsSample.xlsx"); | |
// Access first worksheet. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing the Validations collection of the worksheet | |
Validation validation = worksheet.getValidations().get(0); | |
// Create your cell area. | |
CellArea cellArea = CellArea.createCellArea("D5", "E7"); | |
// Adding the cell area to Validation | |
validation.addArea(cellArea, false, false); | |
// Save the output workbook. | |
workbook.save(outputDir + "ValidationsSample_out.xlsx"); |
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-Java | |
Workbook book = new Workbook(srcDir + "sampleValidation.xlsx"); | |
Worksheet sheet = book.getWorksheets().get("Sheet1"); | |
Cells cells = sheet.getCells(); | |
Cell a2 = cells.get("A2"); | |
Validation va2 = a2.getValidation(); | |
if(va2.getInCellDropDown()) { | |
System.out.println("A2 is a dropdown"); | |
} else { | |
System.out.println("A2 is NOT a dropdown"); | |
} | |
Cell b2 = cells.get("B2"); | |
Validation vb2 = b2.getValidation(); | |
if(vb2.getInCellDropDown()) { | |
System.out.println("B2 is a dropdown"); | |
} else { | |
System.out.println("B2 is NOT a dropdown"); | |
} | |
Cell c2 = cells.get("C2"); | |
Validation vc2 = c2.getValidation(); | |
if(vc2.getInCellDropDown()) { | |
System.out.println("C2 is a dropdown"); | |
} else { | |
System.out.println("C2 is NOT a dropdown"); | |
} |
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-Java | |
// Output directory | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Create union range | |
UnionRange unionRange = workbook.getWorksheets().createUnionRange("sheet1!A1:A10,sheet1!C1:C10", 0); | |
// Put value "ABCD" in the range | |
unionRange.setValue("ABCD"); | |
// Saving the modified Excel file in default format | |
workbook.save(outputDir + "CreateUnionRange_out.xlsx"); |
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-Java | |
// Load the source Excel file | |
Workbook workbook = new Workbook(srcDir + "sampleBackgroundFile.xlsx"); | |
// Instantiate data sorter object | |
DataSorter sorter = workbook.getDataSorter(); | |
// Add key for Column B, Sort it in descending order with background color red | |
sorter.addKey(1, SortOnType.CELL_COLOR, SortOrder.DESCENDING, Color.getRed()); | |
// Sort the data based on the key | |
sorter.sort(workbook.getWorksheets().get(0).getCells(), CellArea.createCellArea("A2", "C6")); | |
// Save the output file | |
workbook.save(outDir + "outputSampleBackgroundFile.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExportingDataFromWorksheets.class) + "Data/"; | |
// Creating a file stream containing the Excel file to be opened | |
FileInputStream fstream = new FileInputStream(dataDir + "book1.xls"); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Exporting the contents of 7 rows and 2 columns starting from 1st cell | |
// to Array. | |
Object dataTable[][] = worksheet.getCells().exportArray(0, 0, 7, 2); | |
// Printing the number of rows exported | |
System.out.println("No. Of Rows Exported: " + dataTable.length); | |
// Closing the file stream to free all resources | |
fstream.close(); |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// The path to the output directory. | |
String outDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sampleMergedTemplate.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
ArrayList productList = new ArrayList(); | |
for(int i = 0; i < 3; i++) { | |
productList.add(new Product("Test Product - " + i, i*2)); | |
} | |
ImportTableOptions tableOptions = new ImportTableOptions(); | |
tableOptions.setCheckMergedCells(true); | |
tableOptions.setFieldNameShown(false); | |
//Insert data to excel template | |
worksheet.getCells().importCustomObjects(productList, 1, 0, tableOptions); | |
workbook.save(outDir + "sampleMergedTemplate_out.xlsx", SaveFormat.XLSX); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ImportingFromJson.class) + "Data/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Read File | |
File file = new File(dataDir + "Test.json"); | |
BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); | |
String jsonInput = ""; | |
String tempString; | |
while ((tempString = bufferedReader.readLine()) != null) { | |
jsonInput = jsonInput + tempString; | |
} | |
bufferedReader.close(); | |
// Set Styles | |
CellsFactory factory = new CellsFactory(); | |
Style style = factory.createStyle(); | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
style.getFont().setColor(Color.getBlueViolet()); | |
style.getFont().setBold(true); | |
// Set JsonLayoutOptions | |
JsonLayoutOptions options = new JsonLayoutOptions(); | |
options.setTitleStyle(style); | |
options.setArrayAsTable(true); | |
// Import JSON Data | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, options); | |
// Save Excel file | |
workbook.save(dataDir + "ImportingFromJson.out.xlsx"); |
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-Java | |
// The path to the output directory. | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.getStyle(); | |
// Setting the font weight to bold | |
style.getFont().setBold(true); | |
// Applying the style to the cell | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save(outputDir + "book1.out.xlsx", SaveFormat.XLSX); |
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-Java | |
public static void main(String[] args) throws Exception { | |
Workbook wb = new Workbook(srcDir + "sampleReplaceTagWithText.xlsx"); | |
String tag = "TAG_2#TAG_1"; | |
String replace = "1#ys"; | |
for (int i = 0; i < tag.split("#").length; i++) { | |
sheetReplace(wb, "<" + tag.split("#")[i] + ">", replace.split("#")[i]); | |
} | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
wb.save(outDir + "outputReplaceTagWithText.pdf", opts); | |
// Print the message | |
System.out.println("ReplaceTagWithTextInTextBox executed successfully."); | |
} | |
public static void sheetReplace(Workbook workbook, String sFind, String sReplace) throws Exception | |
{ | |
String finding = sFind; | |
for (Object obj : workbook.getWorksheets()) { | |
Worksheet sheet = (Worksheet)obj; | |
sheet.replace(finding, sReplace); | |
for (int j = 0; j < 3; j++) { | |
if (sheet.getPageSetup().getHeader(j) != null) { | |
sheet.getPageSetup().setHeader(j, sheet.getPageSetup().getHeader(j).replace(finding, sReplace)); | |
} | |
if (sheet.getPageSetup().getFooter(j) != null) { | |
sheet.getPageSetup().setFooter(j, sheet.getPageSetup().getFooter(j).replace(finding, sReplace)); | |
} | |
} | |
} | |
for (Object obj: workbook.getWorksheets()) { | |
Worksheet sheet = (Worksheet)obj; | |
sFind = sFind.replace("<", "<"); | |
sFind = sFind.replace(">", ">"); | |
for (Object obj1 : sheet.getTextBoxes()) { | |
TextBox mytextbox = (TextBox)obj1; | |
if (mytextbox.getHtmlText() != null) { | |
if (mytextbox.getHtmlText().indexOf(sFind) >= 0) { | |
mytextbox.setHtmlText(mytextbox.getHtmlText().replace(sFind, sReplace)); | |
} | |
} | |
} | |
} | |
} |
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-Java | |
Workbook wb = new Workbook(srcDir + "SmartArt.xlsx"); | |
for (Object obj : wb.getWorksheets()) | |
{ | |
Worksheet worksheet = (Worksheet)obj; | |
for (Object shp : worksheet.getShapes()) | |
{ | |
Shape shape = (Shape)shp; | |
shape.setAlternativeText("ReplacedAlternativeText"); // This works fine just as the normal Shape objects do. | |
if (shape.isSmartArt()) | |
{ | |
for (Shape smartart : shape.getResultOfSmartArt().getGroupedShapes()) | |
{ | |
smartart.setText("ReplacedText"); // This doesn't update the text in Workbook which I save to the another file. | |
} | |
} | |
} | |
} | |
com.aspose.cells.OoxmlSaveOptions options = new com.aspose.cells.OoxmlSaveOptions(); | |
options.setUpdateSmartArt(true); | |
wb.save(outDir + "outputSmartArt.xlsx", options); |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.FODS); | |
// Create a Workbook object and opening the file from its path | |
Workbook workbook = new Workbook(sourceDir + "SampleFods.fods", loadOptions); | |
// Print message | |
System.out.println("FODS file opened successfully!"); |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.SXC); | |
// Create a Workbook object and opening the file from its path | |
Workbook workbook = new Workbook(sourceDir + "SampleSXC.sxc", loadOptions); | |
// Using the Sheet 1 in Workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing a cell using its name | |
Cell cell = worksheet.getCells().get("C3"); | |
System.out.println("Cell Name: " + cell.getName() + " Value: " + cell.getStringValue()); |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.TSV); | |
// Create a Workbook object and opening the file from its path | |
Workbook workbook = new Workbook(sourceDir + "SampleTSVFile.tsv", loadOptions); | |
// Using the Sheet 1 in Workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing a cell using its name | |
Cell cell = worksheet.getCells().get("C3"); | |
System.out.println("Cell Name: " + cell.getName() + " Value: " + cell.getStringValue()); |
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-Java | |
String srcDir = Utils.Get_SourceDirectory(); | |
String outDir = Utils.Get_OutputDirectory(); | |
// Open an Excel file. | |
Workbook workbook = new Workbook( | |
srcDir + "sampleSetDefaultFontPropertyOfPdfSaveOptionsAndImageOrPrintOptions.xlsx"); | |
// Rendering to PNG file format while setting the | |
// CheckWorkbookDefaultFont attribute to false. | |
// So, "Times New Roman" font would be used for any missing (not | |
// installed) font in the workbook. | |
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions(); | |
imgOpt.setImageType(ImageType.PNG); | |
imgOpt.setCheckWorkbookDefaultFont(false); | |
imgOpt.setDefaultFont("Times New Roman"); | |
SheetRender sr = new SheetRender(workbook.getWorksheets().get(0), imgOpt); | |
sr.toImage(0, outDir + "outputSetDefaultFontProperty_ImagePNG.png"); | |
// Rendering to TIFF file format while setting the | |
// CheckWorkbookDefaultFont attribute to false. | |
// So, "Times New Roman" font would be used for any missing (not | |
// installed) font in the workbook. | |
imgOpt.setImageType(ImageType.TIFF); | |
WorkbookRender wr = new WorkbookRender(workbook, imgOpt); | |
wr.toImage(outDir + "outputSetDefaultFontProperty_ImageTIFF.tiff"); | |
// Rendering to PDF file format while setting the | |
// CheckWorkbookDefaultFont attribute to false. | |
// So, "Times New Roman" font would be used for any missing (not | |
// installed) font in the workbook. | |
PdfSaveOptions saveOptions = new PdfSaveOptions(); | |
saveOptions.setDefaultFont("Times New Roman"); | |
saveOptions.setCheckWorkbookDefaultFont(false); | |
workbook.save(outDir + "outputSetDefaultFontProperty_PDF.pdf", saveOptions); |
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-Java | |
// Create empty workbook | |
Workbook workbook = new Workbook(); | |
// Register macro enabled add-in along with the function name | |
int id = workbook.getWorksheets().registerAddInFunction(srcDir + "TESTUDF.xlam", "TEST_UDF", false); | |
// Register more functions in the file (if any) | |
workbook.getWorksheets().registerAddInFunction(id, "TEST_UDF1"); //in this way you can add more functions that are in the same file | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first cell | |
Cell cell = worksheet.getCells().get("A1"); | |
// Set formula name present in the add-in | |
cell.setFormula("=TEST_UDF()"); | |
// Save workbook to output XLSX format. | |
workbook.save(outDir + "test_udf.xlsx", SaveFormat.XLSX); |
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-Java | |
public class DataObject | |
{ | |
private int id; | |
private String name; | |
public DataObject(int id, String name) | |
{ | |
this.id = id; | |
this.name = name; | |
} | |
public int getId() | |
{ | |
return this.id; | |
} | |
public void setId(int value) | |
{ | |
this.id = value; | |
} | |
public String getName() | |
{ | |
return this.name; | |
} | |
public void setName(String value) | |
{ | |
this.name = value; | |
} | |
} |
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-Java | |
public class Product | |
{ | |
String name; | |
int quantity; | |
public Product(String name, int quantity) | |
{ | |
this.quantity = quantity; | |
this.name = name; | |
} | |
public int getQuantity() | |
{ | |
return this.quantity; | |
} | |
public void setQuantity(int value) | |
{ | |
this.quantity = value; | |
} | |
public String getName() | |
{ | |
return this.name; | |
} | |
public void setName(String value) | |
{ | |
this.name = value; | |
} | |
} |
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-Java | |
// Load the Excel file. | |
Workbook wb = new Workbook(srcDir + "sampleInlineCharts.xlsx"); | |
// Access the sheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Set the print area. | |
ws.getPageSetup().setPrintArea("D2:M20"); | |
// Initialize HtmlSaveOptions | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
// Set flag to export print area only | |
options.setExportPrintAreaOnly(true); | |
//Save to HTML format | |
wb.save(outDir + "outputInlineCharts.html",options); |
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-Java | |
// Load the Excel file. | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
// Initialize HtmlSaveOptions | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.setExportHeadings(true); | |
//Save to HTML format | |
workbook.save(outputDir + "PrintHeadings_out.html", options); |
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-Java | |
// Load the sample Excel file containing single sheet only | |
Workbook wb = new Workbook(srcDir + "sampleSingleSheet.xlsx"); | |
// Specify HTML save options | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
// Set optional settings if required | |
options.setEncoding(Encoding.getUTF8()); | |
options.setExportImagesAsBase64(true); | |
options.setExportGridLines(true); | |
options.setExportSimilarBorderStyle(true); | |
options.setExportBogusRowData(true); | |
options.setExcludeUnusedStyles(true); | |
options.setExportHiddenWorksheet(true); | |
//Save the workbook in Html format with specified Html Save Options | |
wb.save(outDir + "outputSampleSingleSheet.htm", options); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitColumnsRowsLoadingHTML.class) + "LoadingSavingConvertingAndManaging/"; | |
//Sample HTML. | |
String sampleHtml = "<html><body><table><tr><td>This is sample text.</td><td>Some text.</td></tr><tr><td>This is another sample text.</td><td>Some text.</td></tr></table></body></html>"; | |
//Load html string into byte array input stream | |
ByteArrayInputStream bais = new ByteArrayInputStream(sampleHtml.getBytes()); | |
//Load byte array stream into workbook. | |
Workbook wb = new Workbook(bais); | |
//Save the workbook in xlsx format. | |
wb.save(dataDir + "outputWithout_AutoFitColsAndRows.xlsx"); | |
//Specify the HtmlLoadOptions and set AutoFitColsAndRows = true. | |
HtmlLoadOptions opts = new HtmlLoadOptions(); | |
opts.setAutoFitColsAndRows(true); | |
//Load byte array stream into workbook with the above HtmlLoadOptions. | |
bais.reset(); | |
wb = new Workbook(bais, opts); | |
//Save the workbook in xlsx format. | |
wb.save(dataDir + "outputWith_AutoFitColsAndRows.xlsx"); |
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-Java | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiate a workbook | |
Workbook workbook = new Workbook(); | |
// Put sample text in the first cell of first worksheet in the newly created workbook | |
workbook.getWorksheets().get(0).getCells().get("A1").setValue("DEMO TEXT ON SHEET1"); | |
// Add second worksheet in the workbook | |
workbook.getWorksheets().add(SheetType.WORKSHEET); | |
// Set text in first cell of the second sheet | |
workbook.getWorksheets().get(1).getCells().get("A1").setValue("DEMO TEXT ON SHEET2"); | |
// Set currently active sheet index to 1 i.e. Sheet2 | |
workbook.getWorksheets().setActiveSheetIndex(1); | |
// Save workbook to SVG. It shall render the active sheet only to SVG | |
workbook.save(outputDir + "ConvertActiveWorksheetToSVG_out.svg"); |
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-Java | |
//Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.CSV); | |
// Load CSV file | |
Workbook workbook = new Workbook(sourceDir + "SampleCsv.csv", loadOptions); | |
Cell lastCell = workbook.getWorksheets().get(0).getCells().getLastCell(); | |
// Set ExportRangeToJsonOptions | |
ExportRangeToJsonOptions options = new ExportRangeToJsonOptions(); | |
Range range = workbook.getWorksheets().get(0).getCells().createRange(0, 0, lastCell.getRow() + 1, lastCell.getColumn() + 1); | |
String data = JsonUtility.exportRangeToJson(range, options); | |
// Print JSON | |
System.out.println(data); |
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-Java | |
//directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Open the template file | |
Workbook workbook = new Workbook(sourceDir + "AddTooltipToHtmlSample.xlsx"); | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.setAddTooltipText(true); | |
// Save as Markdown | |
workbook.save(outputDir + "AddTooltipToHtmlSample_out.html", options); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertExcelFileToMarkdown.class) + "LoadingSavingConvertingAndManaging/"; | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Save as Markdown | |
workbook.save(dataDir + "Book1.md", SaveFormat.MARKDOWN); |
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-Java | |
//Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
//Output directory | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Read JSON file | |
String str = new String(Files.readAllBytes(Paths.get(sourceDir + "SampleJson.json"))); | |
// Create empty workbook | |
Workbook workbook = new Workbook(); | |
// Get Cells | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// Set JsonLayoutOptions | |
JsonLayoutOptions importOptions = new JsonLayoutOptions(); | |
importOptions.setConvertNumericOrDate(true); | |
importOptions.setArrayAsTable(true); | |
importOptions.setIgnoreArrayTitle(true); | |
importOptions.setIgnoreObjectTitle(true); | |
JsonUtility.importData(str, cells, 0, 0, importOptions); | |
// Save Workbook | |
workbook.save(outputDir + "SampleJson_out.csv"); |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// The path to the output directory. | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook wb = new Workbook(sourceDir + "PagesBook1.xlsx"); | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setPageSavingCallback(new TestPageSavingCallback()); | |
wb.save(outputDir + "DocumentConversionProgress.pdf", pdfSaveOptions); |
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-Java | |
class TestPageSavingCallback implements IPageSavingCallback { | |
public void pageStartSaving(PageStartSavingArgs args) | |
{ | |
System.out.println("Start saving page index " + args.getPageIndex() + " of pages " + args.getPageCount()); | |
//don't output pages before page index 2. | |
if (args.getPageIndex() < 2) | |
{ | |
args.setToOutput(false); | |
} | |
} | |
public void pageEndSaving(PageEndSavingArgs args) | |
{ | |
System.out.println("End saving page index " + args.getPageIndex() + " of pages " + args.getPageCount()); | |
//don't output pages after page index 8. | |
if (args.getPageIndex() >= 8) | |
{ | |
args.setHasMorePages(false); | |
} | |
} | |
} |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// The path to the output directory. | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook wb = new Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx"); | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setPageSavingCallback(new TestTiffPageSavingCallback()); | |
opts.setImageType(ImageType.TIFF); | |
WorkbookRender wr = new WorkbookRender(wb, opts); | |
wr.toImage(outputDir + "DocumentConversionProgressForTiff_out.tiff"); |
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-Java | |
class TestTiffPageSavingCallback implements IPageSavingCallback { | |
public void pageStartSaving(PageStartSavingArgs args) | |
{ | |
System.out.println("Start saving page index " + args.getPageIndex() + " of pages " + args.getPageCount()); | |
//don't output pages before page index 2. | |
if (args.getPageIndex() < 2) | |
{ | |
args.setToOutput(false); | |
} | |
} | |
public void pageEndSaving(PageEndSavingArgs args) | |
{ | |
System.out.println("End saving page index " + args.getPageIndex() + " of pages " + args.getPageCount()); | |
//don't output pages after page index 8. | |
if (args.getPageIndex() >= 8) | |
{ | |
args.setHasMorePages(false); | |
} | |
} | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertTableToRangeWithOptions.class) + "LoadingSavingConvertingAndManaging/"; | |
// Open an existing file that contains a table/list object in it | |
Workbook workbook = new Workbook(dataDir + "KeepSeparatorsForBlankRow.xlsx"); | |
// Instantiate Text File's Save Options | |
TxtSaveOptions options = new TxtSaveOptions(); | |
// Set KeepSeparatorsForBlankRow to true show separators in blank rows | |
options.setKeepSeparatorsForBlankRow(true); | |
// Save the file with the options | |
workbook.save(dataDir + "KeepSeparatorsForBlankRow.out.csv", options); |
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-Java | |
//Source directory | |
String dataDir = Utils.getSharedDataDir(OpeningCSVFilesAndReplacingInvalidCharacters.class) + "LoadingSavingConvertingAndManaging/"; | |
LoadOptions loadOptions = new LoadOptions(FileFormatType.CSV); | |
//Load CSV file | |
Workbook workbook = new Workbook(dataDir + "[20180220142533][ASPOSE_CELLS_TEST].csv", loadOptions); | |
System.out.println(workbook.getWorksheets().get(0).getName()); // (20180220142533)(ASPOSE_CELLS_T | |
System.out.println(workbook.getWorksheets().get(0).getName().length()); // 31 | |
System.out.println("CSV file opened successfully!"); |
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-Java | |
class TextParser implements ICustomParser | |
{ | |
@Override | |
public Object parseObject(String s) { | |
return s; | |
} | |
@Override | |
public String getFormat() { | |
return ""; | |
} | |
} | |
class DateParser implements ICustomParser { | |
@Override | |
public Object parseObject(String s) { | |
Date myDate = null; | |
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); | |
try { | |
myDate = formatter.parse(s); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
return myDate; | |
} | |
@Override | |
public String getFormat() { | |
return "dd/MM/yyyy"; | |
} | |
} | |
public class OpeningCSVFilesWithPreferredParser { | |
//Source directory | |
private static String sourceDir = Utils.Get_SourceDirectory(); | |
private static String outputDir = Utils.Get_OutputDirectory(); | |
public static void main(String[] args) throws Exception { | |
// Initialize Text File's Load options | |
TxtLoadOptions oTxtLoadOptions = new TxtLoadOptions(LoadFormat.CSV); | |
// Specify the separatot character | |
oTxtLoadOptions.setSeparator(','); | |
// Specify the encoding scheme | |
oTxtLoadOptions.setEncoding(Encoding.getUTF8()); | |
// Set the flag to true for converting datetime data | |
oTxtLoadOptions.setConvertDateTimeData(true); | |
// Set the preferred parsers | |
oTxtLoadOptions.setPreferredParsers(new ICustomParser[] { new TextParser(), new DateParser() }); | |
// Initialize the workbook object by passing CSV file and text load options | |
Workbook oExcelWorkBook = new Workbook(sourceDir + "samplePreferredParser.csv", oTxtLoadOptions); | |
// Get the first cell | |
Cell oCell = oExcelWorkBook.getWorksheets().get(0).getCells().get("A1"); | |
// Display type of value | |
System.out.println("A1: " + getCellType(oCell.getType()) + " - " + oCell.getDisplayStringValue()); | |
// Get the second cell | |
oCell = oExcelWorkBook.getWorksheets().get(0).getCells().get("B1"); | |
// Display type of value | |
System.out.println("B1: " + getCellType(oCell.getType()) + " - " + oCell.getDisplayStringValue()); | |
// Save the workbook to disc | |
oExcelWorkBook.save(outputDir + "outputsamplePreferredParser.xlsx"); | |
System.out.println("OpeningCSVFilesWithPreferredParser executed successfully.\r\n"); | |
} | |
private static String getCellType(int type){ | |
if(type == CellValueType.IS_STRING){ | |
return "String"; | |
} else if(type == CellValueType.IS_NUMERIC){ | |
return "Numeric"; | |
} else if(type == CellValueType.IS_BOOL){ | |
return "Bool"; | |
} else if(type == CellValueType.IS_DATE_TIME){ | |
return "Date"; | |
} else if(type == CellValueType.IS_NULL){ | |
return "Null"; | |
} else if(type == CellValueType.IS_ERROR){ | |
return "Error"; | |
} else{ | |
return "Unknown"; | |
} | |
} |
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-Java | |
// Opening Microsoft Excel 97 Files | |
// Creating an EXCEL_97_TO_2003 LoadOptions object | |
LoadOptions loadOptions1 = new LoadOptions(FileFormatType.EXCEL_95); | |
// Creating an Workbook object with excel 97 file path and the | |
// loadOptions object | |
new Workbook(srcDir + "Excel95_5.0.xls", loadOptions1); | |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(VerifyPassword.class) + "LoadingSavingConvertingAndManaging/"; | |
// Create a Stream object | |
FileInputStream fstream = new FileInputStream(dataDir + "EncryptedBook1.xlsx"); | |
boolean isPasswordValid = FileFormatUtil.verifyPassword(fstream, "1234"); | |
System.out.println("Password is Valid: " + isPasswordValid); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(WorksheetToImage.class) + "LoadingSavingConvertingAndManaging/"; | |
// Instantiate a new workbook with path to an Excel file | |
Workbook book = new Workbook(dataDir + "MyTestBook1.xlsx"); | |
// Create an object for ImageOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the image type | |
imgOptions.setImageType(ImageType.PNG); | |
// Get the first worksheet. | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Create a SheetRender object for the target sheet | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int j = 0; j < sr.getPageCount(); j++) { | |
// Generate an image for the worksheet | |
sr.toImage(j, dataDir + "WToImage-out" + j + ".png"); | |
} |
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-Java | |
public class CustomizeGlobalizationSettingsforPivotTable { | |
class CustomPivotTableGlobalizationSettings extends GlobalizationSettings | |
{ | |
//Gets the name of "Total" label in the PivotTable. | |
//You need to override this method when the PivotTable contains two or more PivotFields in the data area. | |
public String getPivotTotalName() | |
{ | |
System.out.println("---------GetPivotTotalName-------------"); | |
return "AsposeGetPivotTotalName"; | |
} | |
//Gets the name of "Grand Total" label in the PivotTable. | |
public String getPivotGrandTotalName() | |
{ | |
System.out.println("---------GetPivotGrandTotalName-------------"); | |
return "AsposeGetPivotGrandTotalName"; | |
} | |
//Gets the name of "(Multiple Items)" label in the PivotTable. | |
public String getMultipleItemsName() | |
{ | |
System.out.println("---------GetMultipleItemsName-------------"); | |
return "AsposeGetMultipleItemsName"; | |
} | |
//Gets the name of "(All)" label in the PivotTable. | |
public String getAllName() | |
{ | |
System.out.println("---------GetAllName-------------"); | |
return "AsposeGetAllName"; | |
} | |
//Gets the name of "Column Labels" label in the PivotTable. | |
public String getColumnLabelsOfPivotTable() | |
{ | |
System.out.println("---------GetColumnLabelsOfPivotTable-------------"); | |
return "AsposeGetColumnLabelsOfPivotTable"; | |
} | |
//Gets the name of "Row Labels" label in the PivotTable. | |
public String getRowLabelsNameOfPivotTable() | |
{ | |
System.out.println("---------GetRowLabelsNameOfPivotTable-------------"); | |
return "AsposeGetRowLabelsNameOfPivotTable"; | |
} | |
//Gets the name of "(blank)" label in the PivotTable. | |
public String getEmptyDataName() | |
{ | |
System.out.println("---------GetEmptyDataName-------------"); | |
return "(blank)AsposeGetEmptyDataName"; | |
} | |
//Gets the name of PivotFieldSubtotalType type in the PivotTable. | |
public String getSubTotalName(int subTotalType) | |
{ | |
System.out.println("---------GetSubTotalName-------------"); | |
switch (subTotalType) | |
{ | |
case PivotFieldSubtotalType.SUM: | |
return "AsposeSum";//polish | |
case PivotFieldSubtotalType.COUNT: | |
return "AsposeCount"; | |
case PivotFieldSubtotalType.AVERAGE: | |
return "AsposeAverage"; | |
case PivotFieldSubtotalType.MAX: | |
return "AsposeMax"; | |
case PivotFieldSubtotalType.MIN: | |
return "AsposeMin"; | |
case PivotFieldSubtotalType.PRODUCT: | |
return "AsposeProduct"; | |
case PivotFieldSubtotalType.COUNT_NUMS: | |
return "AsposeCount"; | |
case PivotFieldSubtotalType.STDEV: | |
return "AsposeStdDev"; | |
case PivotFieldSubtotalType.STDEVP: | |
return "AsposeStdDevp"; | |
case PivotFieldSubtotalType.VAR: | |
return "AsposeVar"; | |
case PivotFieldSubtotalType.VARP: | |
return "AsposeVarp"; | |
} | |
return "AsposeSubTotalName"; | |
} | |
} | |
public void RunCustomizeGlobalizationSettingsforPivotTable() throws Exception | |
{ | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CustomizeGlobalizationSettingsforPivotTable.class) + "PivotTables/"; | |
//Load your excel file | |
Workbook wb = new Workbook(dataDir + "samplePivotTableGlobalizationSettings.xlsx"); | |
//Setting Custom Pivot Table Globalization Settings | |
wb.getSettings().setGlobalizationSettings(new CustomPivotTableGlobalizationSettings()); | |
//Hide first worksheet that contains the data of the pivot table | |
wb.getWorksheets().get(0).setVisible(false); | |
//Access second worksheet | |
Worksheet ws = wb.getWorksheets().get(1); | |
//Access the pivot table, refresh and calculate its data | |
PivotTable pt = ws.getPivotTables().get(0); | |
pt.setRefreshDataFlag(true); | |
pt.refreshData(); | |
pt.calculateData(); | |
pt.setRefreshDataFlag(false); | |
//Pdf save options - save entire worksheet on a single pdf page | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setOnePagePerSheet(true); | |
//Save the output pdf | |
wb.save(dataDir + "outputPivotTableGlobalizationSettings.pdf", options); | |
} | |
public static void main(String[] args) throws Exception { | |
CustomizeGlobalizationSettingsforPivotTable pg = new CustomizeGlobalizationSettingsforPivotTable(); | |
pg.RunCustomizeGlobalizationSettingsforPivotTable(); | |
} |
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-Java | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(srcDir + "sourcePivotTable.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first pivot table inside the worksheet | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Access pivot table refresh by who property | |
System.out.println("Pivot table refresh by who = " + pivotTable.getRefreshedByWho()); | |
// Access pivot table refresh date | |
System.out.println("Pivot table refresh date = " + pivotTable.getRefreshDate()); |
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-Java | |
// The path to the output directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook wb = new Workbook(sourceDir + "SamplePivotSort.xlsx"); | |
// Obtaining the reference of the newly added worksheet | |
Worksheet sheet = wb.getWorksheets().get(0); | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
// source PivotTable | |
// Adding a PivotTable to the worksheet | |
int index = pivotTables.add("=Sheet1!A1:C10", "E3", "PivotTable2"); | |
//Accessing the instance of the newly added PivotTable | |
PivotTable pivotTable = pivotTables.get(index); | |
// Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
pivotTable.setColumnGrand(false); | |
// Dragging the first field to the row area. | |
pivotTable.addFieldToArea(PivotFieldType.ROW, 1); | |
PivotField rowField = pivotTable.getRowFields().get(0); | |
rowField.setAutoSort(true); | |
rowField.setAscendSort(true); | |
// Dragging the second field to the column area. | |
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 0); | |
PivotField colField = pivotTable.getColumnFields().get(0); | |
colField.setNumberFormat("dd/mm/yyyy"); | |
colField.setAutoSort(true); | |
colField.setAscendSort(true); | |
// Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// end of source PivotTable | |
// sort the PivotTable on "SeaFood" row field values | |
// Adding a PivotTable to the worksheet | |
index = pivotTables.add("=Sheet1!A1:C10", "E10", "PivotTable2"); | |
// Accessing the instance of the newly added PivotTable | |
pivotTable = pivotTables.get(index); | |
// Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
pivotTable.setColumnGrand(false); | |
// Dragging the first field to the row area. | |
pivotTable.addFieldToArea(PivotFieldType.ROW, 1); | |
rowField = pivotTable.getRowFields().get(0); | |
rowField.setAutoSort(true); | |
rowField.setAscendSort(true); | |
// Dragging the second field to the column area. | |
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 0); | |
colField = pivotTable.getColumnFields().get(0); | |
colField.setNumberFormat("dd/mm/yyyy"); | |
colField.setAutoSort(true); | |
colField.setAscendSort(true); | |
colField.setAutoSortField(0); | |
//Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// end of sort the PivotTable on "SeaFood" row field values | |
// sort the PivotTable on "28/07/2000" column field values | |
// Adding a PivotTable to the worksheet | |
index = pivotTables.add("=Sheet1!A1:C10", "E18", "PivotTable2"); | |
// Accessing the instance of the newly added PivotTable | |
pivotTable = pivotTables.get(index); | |
// Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
pivotTable.setColumnGrand(false); | |
// Dragging the first field to the row area. | |
pivotTable.addFieldToArea(PivotFieldType.ROW, 1); | |
rowField = pivotTable.getRowFields().get(0); | |
rowField.setAutoSort(true); | |
rowField.setAscendSort(true); | |
rowField.setAutoSortField(0); | |
// Dragging the second field to the column area. | |
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 0); | |
colField = pivotTable.getColumnFields().get(0); | |
colField.setNumberFormat("dd/mm/yyyy"); | |
colField.setAutoSort(true); | |
colField.setAscendSort(true); | |
// Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// end of sort the PivotTable on "28/07/2000" column field values | |
//Saving the Excel file | |
wb.save(outputDir + "out_java.xlsx"); | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setOnePagePerSheet(true); | |
wb.save(outputDir + "out_java.pdf", options); |
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-Java | |
// directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Load a template file | |
Workbook workbook = new Workbook(sourceDir + "PivotTableSample.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
int pivotIndex = 0; | |
// Get the pivot tables in the sheet | |
PivotTable pivotTable = sheet.getPivotTables().get(pivotIndex); | |
// Accessing the data fields. | |
PivotFieldCollection pivotFields = pivotTable.getDataFields(); | |
// Accessing the first data field in the data fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting data display format | |
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST); | |
pivotTable.calculateData(); | |
// Saving the Excel file | |
workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx"); |
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-Java | |
// Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// Load sample file | |
Workbook workbook = new Workbook(sourceDir + "SamplePivotTableExternalConnection.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the pivot table | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Print External Connection Details | |
System.out.println("External Connection Data Source"); | |
System.out.println("Name: " + pivotTable.getExternalConnectionDataSource().getName()); | |
System.out.println("Type: " + pivotTable.getExternalConnectionDataSource().getType()); |
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-Java | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the newly added worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
Cells cells = sheet.getCells(); | |
// Setting the value to the cells | |
Cell cell = cells.get("A1"); | |
cell.putValue("Sport"); | |
cell = cells.get("B1"); | |
cell.putValue("Quarter"); | |
cell = cells.get("C1"); | |
cell.putValue("Sales"); | |
cell = cells.get("A2"); | |
cell.putValue("Golf"); | |
cell = cells.get("A3"); | |
cell.putValue("Golf"); | |
cell = cells.get("A4"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A5"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A6"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A7"); | |
cell.putValue("Tennis"); | |
cell = cells.get("A8"); | |
cell.putValue("Golf"); | |
cell = cells.get("B2"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("B3"); | |
cell.putValue("Qtr4"); | |
cell = cells.get("B4"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("B5"); | |
cell.putValue("Qtr4"); | |
cell = cells.get("B6"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("B7"); | |
cell.putValue("Qtr4"); | |
cell = cells.get("B8"); | |
cell.putValue("Qtr3"); | |
cell = cells.get("C2"); | |
cell.putValue(1500); | |
cell = cells.get("C3"); | |
cell.putValue(2000); | |
cell = cells.get("C4"); | |
cell.putValue(600); | |
cell = cells.get("C5"); | |
cell.putValue(1500); | |
cell = cells.get("C6"); | |
cell.putValue(4070); | |
cell = cells.get("C7"); | |
cell.putValue(5000); | |
cell = cells.get("C8"); | |
cell.putValue(6430); | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
// Adding a PivotTable to the worksheet | |
int index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
// Accessing the instance of the newly added PivotTable | |
PivotTable pivotTable = pivotTables.get(index); | |
// Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
// Draging the first field to the row area. | |
pivotTable.addFieldToArea(PivotFieldType.ROW, 0); | |
// Draging the second field to the column area. | |
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1); | |
// Draging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
pivotTable.calculateData(); | |
// Saving the ODS file | |
workbook.save(outputDir + "PivotTableSaveInODS_out.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-Java | |
// The path to the output directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "PivotTableHideAndSortSample.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
CellArea dataBodyRange = pivotTable.getDataBodyRange(); | |
int currentRow = 3; | |
int rowsUsed = dataBodyRange.EndRow; | |
// Sorting score in descending | |
PivotField field = pivotTable.getRowFields().get(0); | |
field.setAutoSort(true); | |
field.setAscendSort(false); | |
field.setAutoSortField(0); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Hiding rows with score less than 60 | |
while (currentRow < rowsUsed) | |
{ | |
Cell cell = worksheet.getCells().get(currentRow, 1); | |
double score = (double) cell.getValue(); | |
if (score < 60) | |
{ | |
worksheet.getCells().hideRow(currentRow); | |
} | |
currentRow++; | |
} | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Saving the Excel file | |
workbook.save(outputDir + "PivotTableHideAndSort_out.xlsx"); |
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-Java | |
// Load template file | |
Workbook wb = new Workbook(srcDir + "samplePivotTable.xlsx"); | |
// Get first pivot table in the worksheet | |
PivotTable pt = wb.getWorksheets().get(1).getPivotTables().get(0); | |
// Set pivot field | |
pt.showReportFilterPage(pt.getPageFields().get(0)); | |
// Set position index for showing report filter pages | |
pt.showReportFilterPageByIndex(pt.getPageFields().get(0).getPosition()); | |
// Set the page field name | |
pt.showReportFilterPageByName(pt.getPageFields().get(0).getName()); | |
// Save the output file | |
wb.save(outDir + "outputSamplePivotTable.xlsx"); |
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-Java | |
String outDir = Utils.Get_OutputDirectory(); | |
// Create workbook | |
Workbook wb = new Workbook(); | |
// Access first worksheet - it is empty sheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Specify image or print options | |
// Since the sheet is blank, we will set | |
// OutputBlankPageWhenNothingToPrint to true | |
// So that empty page gets printed | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setImageType(ImageType.PNG); | |
opts.setOutputBlankPageWhenNothingToPrint(true); | |
// Render empty sheet to png image | |
SheetRender sr = new SheetRender(ws, opts); | |
sr.toImage(0, outDir + "OutputBlankPageWhenNothingToPrint.png"); |
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-Java | |
//Load the sample Excel file | |
Workbook wb = new Workbook(srcDir + "sampleImageOrPrintOptions_PageIndexPageCount.xlsx"); | |
//Access the first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Specify image or print options | |
//We want to print pages 4, 5, 6, 7 | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setPageIndex(3); | |
opts.setPageCount(4); | |
opts.setImageType(ImageType.PNG); | |
//Create sheet render object | |
SheetRender sr = new SheetRender(ws, opts); | |
//Print all the pages as images | |
for (int i = opts.getPageIndex(); i < sr.getPageCount(); i++) | |
{ | |
sr.toImage(i, outDir + "outputImage-" + (i+1) + ".png"); | |
} |
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-Java | |
// Load the template file | |
Workbook wb = new Workbook(srcDir + "sampleCrosssType.xlsx"); | |
// Initialize PDF save options | |
PdfSaveOptions saveOptions = new PdfSaveOptions(); | |
// Set text criss type | |
saveOptions.setTextCrossType(TextCrossType.STRICT_IN_CELL); | |
// Save output PDF file | |
wb.save(outDir + "outputCrosssType.pdf", saveOptions); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutofitRowsforMergedCells.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Create a range A1:B1 | |
Range range = worksheet.getCells().createRange(0, 0, 1, 2); | |
// Merge the cells | |
range.merge(); | |
// Insert value to the merged cell A1 | |
worksheet.getCells().get(0, 0).setValue("A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end"); | |
// Create a style object | |
Style style = worksheet.getCells().get(0, 0).getStyle(); | |
// Set wrapping text on | |
style.setTextWrapped(true); | |
// Apply the style to the cell | |
worksheet.getCells().get(0, 0).setStyle(style); | |
// Create an object for AutoFitterOptions | |
AutoFitterOptions options = new AutoFitterOptions(); | |
// Set auto-fit for merged cells | |
options.setAutoFitMergedCellsType(AutoFitMergedCellsType.EACH_LINE); | |
// Autofit rows in the sheet(including the merged cells) | |
worksheet.autoFitRows(options); | |
// Save the Excel file | |
workbook.save(dataDir + "AutofitRowsforMergedCells_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(GroupingRowsandColumns.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by | |
// passing true | |
cells.groupRows(0, 5, true); | |
// Grouping first three columns (from 0 to 2) and making them hidden by | |
// passing true | |
cells.groupColumns(0, 2, true); | |
// Setting SummaryRowBelow property to false | |
worksheet.getOutline().setSummaryRowBelow(true); | |
// Setting SummaryColumnRight property to false | |
worksheet.getOutline().setSummaryColumnRight(true); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "GroupingRowsandColumns_out.xlsx"); |
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-Java | |
String dataDir = Utils.getSharedDataDir(InsertingARowWithFormatting.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Setting Formatting options | |
InsertOptions insertOptions = new InsertOptions(); | |
insertOptions.setCopyFormatType(CopyFormatType.SAME_AS_ABOVE); | |
// Inserting a row into the worksheet at 3rd position | |
worksheet.getCells().insertRows(2, 1, insertOptions); | |
// Saving the modified Excel file | |
workbook.save(dataDir + "InsertingARowWithFormatting_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Set the width of the cell in pixels | |
worksheet.getCells().setViewColumnWidthPixel(7, 200); | |
workbook.save(dataDir + "SetColumnViewWidthInPixels_Out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SummaryRowBelow.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by passing true | |
cells.groupRows(0, 5, true); | |
// Grouping first three columns (from 0 to 2) and making them hidden by passing true | |
cells.groupColumns(0, 2, true); | |
// Setting SummaryRowBelow property to false | |
worksheet.getOutline().setSummaryRowBelow(false); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SummaryRowBelow_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SummaryRowRight.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "BookStyles.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by passing true | |
cells.ungroupRows(0, 5); | |
// Grouping first three columns (from 0 to 2) and making them hidden by passing true | |
cells.ungroupColumns(0, 2); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SummaryRowRight_out.xls"); |
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-Java | |
// Load sample Excel file containing a table. | |
Workbook workbook = new Workbook(sourceDir + "sampleCreateSlicerToExcelTable.xlsx"); | |
// Access first worksheet. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first table inside the worksheet. | |
ListObject table = worksheet.getListObjects().get(0); | |
// Add slicer | |
int idx = worksheet.getSlicers().add(table, 0, "H5"); | |
Slicer slicer = worksheet.getSlicers().get(idx); | |
slicer.setPlacement(PlacementType.FREE_FLOATING); | |
slicer.setRowHeightPixel(50); | |
slicer.setWidthPixel(500); | |
slicer.setTitle("Aspose"); | |
slicer.setAlternativeText("Alternate Text"); | |
slicer.setPrintable(false); | |
slicer.setLocked(false); | |
// Refresh the slicer. | |
slicer.refresh(); | |
// Save the workbook in output XLSX format. | |
workbook.save(outputDir + "outputChangeSlicerProperties.xlsx", SaveFormat.XLSX); |
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-Java | |
// Load sample Excel file containing a table. | |
Workbook workbook = new Workbook(sourceDir + "sampleCreateSlicerToExcelTable.xlsx"); | |
// Access first worksheet. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first table inside the worksheet. | |
ListObject table = worksheet.getListObjects().get(0); | |
// Add slicer | |
int idx = worksheet.getSlicers().add(table, 0, "H5"); | |
// Save the workbook in output XLSX format. | |
workbook.save(outputDir + "outputCreateSlicerToExcelTable.xlsx", SaveFormat.XLSX); |
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-Java | |
Workbook workbook = new Workbook(sourceDir + "SampleSlicerChart.xlsx"); | |
workbook.save(outputDir + "SampleSlicerChart.pdf", SaveFormat.PDF); |
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-Java | |
// Load sample Excel file containing slicer. | |
Workbook wb = new Workbook(srcDir + "sampleRenderingSlicer.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Set the print area because we want to render slicer only. | |
ws.getPageSetup().setPrintArea("B15:E25"); | |
// Specify image or print options, set one page per sheet and only area to true. | |
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions(); | |
imgOpts.setHorizontalResolution(200); | |
imgOpts.setVerticalResolution(200); | |
imgOpts.setImageType(com.aspose.cells.ImageType.PNG); | |
imgOpts.setOnePagePerSheet(true); | |
imgOpts.setOnlyArea(true); | |
// Create sheet render object and render worksheet to image. | |
SheetRender sr = new SheetRender(ws, imgOpts); | |
sr.toImage(0, outDir + "outputRenderingSlicer.png"); |
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-Java | |
//Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
//Output directory | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Open an existing file that contains a table/list object in it | |
Workbook workbook = new Workbook(sourceDir + "SampleTable.xlsx"); | |
// Save the file | |
workbook.save(outputDir + "ConvertTableToOds_out.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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertTableToRangeWithOptions.class) + "Tables/"; | |
// Open an existing file that contains a table/list object in it | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
TableToRangeOptions options = new TableToRangeOptions(); | |
options.setLastRow(5); | |
// Convert the first table/list object (from the first worksheet) to normal range | |
workbook.getWorksheets().get(0).getListObjects().get(0).convertToRange(options); | |
// Save the file | |
workbook.save(dataDir + "ConvertTableToRangeWithOptions_out.xlsx"); |
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-Java | |
// The path to the output directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Load workbook object | |
Workbook workbook = new Workbook(sourceDir + "SampleTableWithQueryTable.xls"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
ListObject table = worksheet.getListObjects().get(0); | |
// Check the data source type if it is query table | |
if (table.getDataSourceType() == TableDataSourceType.QUERY_TABLE) | |
{ | |
table.setShowTotals(true); | |
} | |
// Save the file | |
workbook.save(outputDir + "SampleTableWithQueryTable_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitRowsforMergedCells.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first (default) worksheet | |
Worksheet _worksheet = workbook.getWorksheets().get(0); | |
// Create a range A1:B1 | |
Range range = _worksheet.getCells().createRange(0, 0, 1, 2); | |
// Merge the cells | |
range.merge(); | |
// Insert value to the merged cell A1 | |
_worksheet.getCells().get(0, 0).setValue( | |
"A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end"); | |
// Create a style object | |
Style style = _worksheet.getCells().get(0, 0).getStyle(); | |
// Set wrapping text on | |
style.setTextWrapped(true); | |
// Apply the style to the cell | |
_worksheet.getCells().get(0, 0).setStyle(style); | |
// Create an object for AutoFitterOptions | |
AutoFitterOptions options = new AutoFitterOptions(); | |
// Set auto-fit for merged cells | |
options.setAutoFitMergedCellsType(AutoFitMergedCellsType.EACH_LINE); | |
// Autofit rows in the sheet(including the merged cells) | |
_worksheet.autoFitRows(options); | |
// Save the Excel file | |
workbook.save(dataDir + "AFRFMergedCells.xlsx"); |
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-Java | |
String dataDir = Utils.Get_OutputDirectory(); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Add some text in cell A1 | |
worksheet.getCells().get("A1").putValue("Here"); | |
// Add a comment to A1 cell | |
Comment comment = worksheet.getComments().get(worksheet.getComments().add("A1")); | |
// Set its vertical alignment setting | |
comment.getCommentShape().setTextVerticalAlignment(TextAlignmentType.CENTER); | |
// Set the Comment note | |
comment.setNote("This is my Comment Text. This is test"); | |
Shape shape = worksheet.getComments().get("A1").getCommentShape(); | |
shape.getFill().getSolidFill().setColor(Color.getBlack()); | |
Font font = shape.getFont(); | |
font.setColor(Color.getWhite()); | |
StyleFlag styleFlag = new StyleFlag(); | |
styleFlag.setFontColor(true); | |
shape.getTextBody().format(0, shape.getText().length(), font, styleFlag); | |
// Save the Excel file | |
workbook.save(dataDir + "outputChangeCommentFontColor.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CheckForShapes.class) + "TechnicalArticles/"; | |
// Create an instance of Workbook and load an existing spreadsheet | |
Workbook workbook = new Workbook(dataDir + "SampleCheckCells.xlsx"); | |
// Loop over all worksheets in the workbook | |
for (int i = 0; i < workbook.getWorksheets().getCount(); i++) { | |
Worksheet worksheet = workbook.getWorksheets().get(i); | |
// Check if worksheet has populated cells | |
if (worksheet.getCells().getMaxDataRow() != -1) { | |
System.out.println(worksheet.getName() + " is not empty because one or more cells are populated"); | |
} | |
// Check if worksheet has shapes | |
else if (worksheet.getShapes().getCount() > 0) { | |
System.out.println(worksheet.getName() + " is not empty because there are one or more shapes"); | |
} | |
// Check if worksheet has empty initialized cells | |
else { | |
Range range = worksheet.getCells().getMaxDisplayRange(); | |
Iterator rangeIterator = range.iterator(); | |
if (rangeIterator.hasNext()) { | |
System.out.println(worksheet.getName() + " is not empty because one or more cells are initialized"); | |
} else { | |
System.out.println(worksheet.getName() + " is empty"); | |
} | |
} | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConversionOptions.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook object | |
// Open template | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Horizontal Resolution | |
options.setHorizontalResolution(300); | |
// Set Vertical Resolution | |
options.setVerticalResolution(300); | |
// Set Image Format | |
options.setImageType(ImageType.JPEG); | |
// If you want entire sheet as a single image | |
options.setOnePagePerSheet(true); | |
// Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, options); | |
// Render/save the image for the sheet | |
sr.toImage(0, dataDir + "ConversionOptions_out.jpg"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertWorkbooktoImage.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook object | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Image Format | |
options.setImageType(ImageType.TIFF); | |
// If you want entire sheet as a single image | |
options.setOnePagePerSheet(true); | |
// Render to image | |
WorkbookRender render = new WorkbookRender(book, options); | |
render.toImage(dataDir + "CWorkbooktoImage_out.tiff"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertWorksheettoImage.class) + "TechnicalArticles/"; | |
//Instantiate a new Workbook object | |
//Open template | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
//Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
//Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
//Set Horizontal Resolution | |
options.setHorizontalResolution(300); | |
//Set Vertical Resolution | |
options.setVerticalResolution(300); | |
//Set TiffCompression | |
options.setTiffCompression(TiffCompression.COMPRESSION_LZW); | |
//Set Image Format | |
options.setImageType(ImageType.TIFF); | |
//Set printing page type | |
options.setPrintingPage(PrintingPageType.DEFAULT); | |
//Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, options); | |
//Render/save the image for the sheet | |
sr.toImage(0, dataDir + "CWorksheettoImage_out.tiff"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertWorksheetToImageByPage.class) + "TechnicalArticles/"; | |
// Create a new Workbook object | |
// Open a template excel file | |
Workbook book = new Workbook(dataDir + "ConvertWorksheetToImageByPage.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Resolution | |
options.setHorizontalResolution(200); | |
options.setVerticalResolution(200); | |
options.setImageType(ImageType.TIFF); | |
// Sheet2Image by page conversion | |
SheetRender render = new SheetRender(sheet, options); | |
for (int j = 0; j < render.getPageCount(); j++) { | |
render.toImage(j, dataDir + sheet.getName() + " Page" + (j + 1) + ".tif"); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertWorksheettoImageFile.class) + "TechnicalArticles/"; | |
// Create a new Workbook object | |
// Open a template excel file | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Specify the image format | |
imgOptions.setImageType(ImageType.JPEG); | |
// Render the sheet with respect to specified image/print options | |
SheetRender render = new SheetRender(sheet, imgOptions); | |
// Render the image for the sheet | |
render.toImage(0, dataDir + "CWToImageFile.jpg"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreatePieChartWithLeaderLines.class) + "TechnicalArticles/"; | |
// Create an instance of Workbook in XLSX format | |
Workbook workbook = new Workbook(FileFormatType.XLSX); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Add two columns of data | |
worksheet.getCells().get("A1").putValue("Retail"); | |
worksheet.getCells().get("A2").putValue("Services"); | |
worksheet.getCells().get("A3").putValue("Info & Communication"); | |
worksheet.getCells().get("A4").putValue("Transport Equip"); | |
worksheet.getCells().get("A5").putValue("Construction"); | |
worksheet.getCells().get("A6").putValue("Other Products"); | |
worksheet.getCells().get("A7").putValue("Wholesale"); | |
worksheet.getCells().get("A8").putValue("Land Transport"); | |
worksheet.getCells().get("A9").putValue("Air Transport"); | |
worksheet.getCells().get("A10").putValue("Electric Appliances"); | |
worksheet.getCells().get("A11").putValue("Securities"); | |
worksheet.getCells().get("A12").putValue("Textiles & Apparel"); | |
worksheet.getCells().get("A13").putValue("Machinery"); | |
worksheet.getCells().get("A14").putValue("Metal Products"); | |
worksheet.getCells().get("A15").putValue("Cash"); | |
worksheet.getCells().get("A16").putValue("Banks"); | |
worksheet.getCells().get("B1").putValue(10.4); | |
worksheet.getCells().get("B2").putValue(5.2); | |
worksheet.getCells().get("B3").putValue(6.4); | |
worksheet.getCells().get("B4").putValue(10.4); | |
worksheet.getCells().get("B5").putValue(7.9); | |
worksheet.getCells().get("B6").putValue(4.1); | |
worksheet.getCells().get("B7").putValue(3.5); | |
worksheet.getCells().get("B8").putValue(5.7); | |
worksheet.getCells().get("B9").putValue(3); | |
worksheet.getCells().get("B10").putValue(14.7); | |
worksheet.getCells().get("B11").putValue(3.6); | |
worksheet.getCells().get("B12").putValue(2.8); | |
worksheet.getCells().get("B13").putValue(7.8); | |
worksheet.getCells().get("B14").putValue(2.4); | |
worksheet.getCells().get("B15").putValue(1.8); | |
worksheet.getCells().get("B16").putValue(10.1); | |
// Create a pie chart and add it to the collection of charts | |
int id = worksheet.getCharts().add(ChartType.PIE, 3, 3, 23, 13); | |
// Access newly created Chart instance | |
Chart chart = worksheet.getCharts().get(id); | |
// Set series data range | |
chart.getNSeries().add("B1:B16", true); | |
// Set category data range | |
chart.getNSeries().setCategoryData("A1:A16"); | |
// Turn off legend | |
chart.setShowLegend(false); | |
// Access data labels | |
DataLabels dataLabels = chart.getNSeries().get(0).getDataLabels(); | |
// Turn on category names | |
dataLabels.setShowCategoryName(true); | |
// Turn on percentage format | |
dataLabels.setShowPercentage(true); | |
// Set position | |
dataLabels.setPosition(LabelPositionType.OUTSIDE_END); | |
// Set separator | |
dataLabels.setSeparator(DataLablesSeparatorType.COMMA); | |
//Turn on leader lines | |
chart.getNSeries().get(0).setHasLeaderLines(true); | |
//Calculate chart | |
chart.calculate(); | |
//You need to move DataLabels a little leftward or rightward depending on their position | |
//to show leader lines | |
int DELTA = 100; | |
for (int i = 0; i < chart.getNSeries().get(0).getPoints().getCount(); i++) | |
{ | |
int X = chart.getNSeries().get(0).getPoints().get(i).getDataLabels().getX(); | |
//If it is greater than 2000, then move the X position a little right | |
//otherwise move the X position a little left | |
if (X > 2000) | |
chart.getNSeries().get(0).getPoints().get(i).getDataLabels().setX(X + DELTA); | |
else | |
chart.getNSeries().get(0).getPoints().get(i).getDataLabels().setX(X - DELTA); | |
} | |
//In order to save the chart image, create an instance of ImageOrPrintOptions | |
ImageOrPrintOptions anOption = new ImageOrPrintOptions(); | |
//Set image format | |
anOption.setImageType(ImageType.PNG); | |
//Set resolution | |
anOption.setHorizontalResolution(200); | |
anOption.setVerticalResolution(200); | |
//Render chart to image | |
chart.toImage(dataDir + "CPieChartWLLines_out.png", anOption); | |
//Save the workbook to see chart inside the Excel | |
workbook.save(dataDir + "CPieChartWLLines_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreateTransparentImage.class) + "TechnicalArticles/"; | |
// Create workbook object from source file | |
Workbook wb = new Workbook(dataDir + "aspose-sample.xlsx"); | |
// Apply different image or print options | |
ImageOrPrintOptions imgOption = new ImageOrPrintOptions(); | |
imgOption.setImageType(ImageType.PNG); | |
imgOption.setHorizontalResolution(200); | |
imgOption.setVerticalResolution(200); | |
imgOption.setOnePagePerSheet(true); | |
// Apply transparency to the output image | |
imgOption.setTransparent(true); | |
// Create image after apply image or print options | |
SheetRender sr = new SheetRender(wb.getWorksheets().get(0), imgOption); | |
sr.toImage(0, dataDir + "CTransparentImage_out.png"); |
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-Java | |
import java.util.ArrayList; | |
import com.aspose.cells.AbstractCalculationEngine; | |
import com.aspose.cells.CalculationData; | |
import com.aspose.cells.DateTime; | |
public class CustomFunctionStaticValue extends AbstractCalculationEngine { | |
@Override | |
public void calculate(CalculationData calculationData) { | |
calculationData.setCalculatedValue(new Object[][] { new Object[] { new DateTime(2015, 6, 12, 10, 6, 30), 2 }, | |
new Object[] { 3.0, "Test" } }); | |
} | |
} |
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-Java | |
//Source directory | |
String dataDir = AsposeCellsExamples.Utils.getSharedDataDir(DetectFileFormatOfEncryptedFiles.class) + "TechnicalArticles/"; | |
String filename = dataDir + "encryptedBook1.out.tmp"; | |
FileFormatInfo fileFormatInfo = FileFormatUtil.detectFileFormat(filename,"1234"); // The password is 1234 | |
if(fileFormatInfo.getFileFormatType() == FileFormatType.EXCEL_97_TO_2003) { | |
System.out.println("File Format: EXCEL_97_TO_2003"); | |
} else if(fileFormatInfo.getFileFormatType() == FileFormatType.PPTX) { | |
System.out.println("File Format: PPTX"); | |
} else if(fileFormatInfo.getFileFormatType() == FileFormatType.DOCX) { | |
System.out.println("File Format: DOCX"); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExportRangeofCells.class) + "TechnicalArticles/"; | |
// Create workbook from source file. | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Set the print area with your desired range | |
worksheet.getPageSetup().setPrintArea("E8:H10"); | |
// Set all margins as 0 | |
worksheet.getPageSetup().setLeftMargin(0); | |
worksheet.getPageSetup().setRightMargin(0); | |
worksheet.getPageSetup().setTopMargin(0); | |
worksheet.getPageSetup().setBottomMargin(0); | |
// Set OnePagePerSheet option as true | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
options.setOnePagePerSheet(true); | |
options.setImageType(ImageType.JPEG); | |
// Take the image of your worksheet | |
SheetRender sr = new SheetRender(worksheet, options); | |
sr.toImage(0, dataDir + "ERangeofCells_out.jpg"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExportWorksheettoImage.class) + "TechnicalArticles/"; | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
/* | |
* Set image or print options, We want one page per sheet, The image format is in png And desired dimensions are | |
* 400x400 | |
*/ | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setImageType(ImageType.PNG); | |
opts.setDesiredSize(400, 400); | |
// Render sheet into image | |
SheetRender sr = new SheetRender(worksheet, opts); | |
sr.toImage(0, dataDir + "EWSheetToImage_out.png"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExtractImagesfromWorksheets.class) + "TechnicalArticles/"; | |
// Open a template Excel file | |
Workbook workbook = new Workbook(dataDir + "book3.xlsx"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the first Picture in the first worksheet | |
Picture pic = worksheet.getPictures().get(0); | |
// Set the output image file path | |
String fileName = "aspose-logo.jpg"; | |
// Note: you may evaluate the image format before specifying the image path | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions printoption = new ImageOrPrintOptions(); | |
// Specify the image format | |
printoption.setImageType(ImageType.JPEG); | |
// Save the image | |
pic.toImage(dataDir + fileName, printoption); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(FilterDataWhileLoadingWorkbook.class) + "TechnicalArticles/"; | |
// Set the load options, we only want to load shapes and do not want to load data | |
LoadOptions opts = new LoadOptions(LoadFormat.XLSX); | |
opts.getLoadFilter().setLoadDataFilterOptions(LoadDataFilterOptions.SHAPE); | |
// Create workbook object from sample excel file using load options | |
Workbook wb = new Workbook(dataDir + "sampleFilterDataWhileLoadingWorkbook.xlsx", opts); | |
// Save the output in PDF format | |
wb.save(dataDir + "sampleFilterDataWhileLoadingWorkbook_out.pdf", SaveFormat.PDF); |
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-Java | |
public class FilterObjectsLoadingWorksheets { | |
// Implement your own custom load filter, it will enable you to filter your | |
// individual worksheet | |
class CustomLoadFilter extends LoadFilter { | |
public void startSheet(Worksheet sheet) { | |
if (sheet.getName().equals("NoCharts")) { | |
// Load everything and filter charts | |
this.setLoadDataFilterOptions(LoadDataFilterOptions.ALL& ~LoadDataFilterOptions.CHART); | |
} | |
if (sheet.getName().equals("NoShapes")) { | |
// Load everything and filter shapes | |
this.setLoadDataFilterOptions(LoadDataFilterOptions.ALL& ~LoadDataFilterOptions.DRAWING); | |
} | |
if (sheet.getName().equals("NoConditionalFormatting")) { | |
// Load everything and filter conditional formatting | |
this.setLoadDataFilterOptions(LoadDataFilterOptions.ALL& ~LoadDataFilterOptions.CONDITIONAL_FORMATTING); | |
} | |
}// End StartSheet method. | |
}// End CustomLoadFilter class. | |
public static void main(String[] args) throws Exception { | |
FilterObjectsLoadingWorksheets pg = new FilterObjectsLoadingWorksheets(); | |
pg.Run(); | |
} | |
public void Run() throws Exception { | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(FilterObjectsLoadingWorksheets.class) + "TechnicalArticles/"; | |
// Filter worksheets using custom load filter | |
LoadOptions ldOpts = new LoadOptions(); | |
ldOpts.setLoadFilter(new CustomLoadFilter()); | |
// Load the workbook with above filter | |
Workbook wb = new Workbook(dataDir + "sampleFilterDifferentObjects.xlsx", ldOpts); | |
// Take the image of all worksheets one by one | |
for (int i = 0; i < wb.getWorksheets().getCount(); i++) { | |
// Access worksheet at index i | |
Worksheet ws = wb.getWorksheets().get(i); | |
// Create image or print options, we want the image of entire | |
// worksheet | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setImageType(ImageType.PNG); | |
// Convert worksheet into image | |
SheetRender sr = new SheetRender(ws, opts); | |
sr.toImage(0, dataDir + ws.getName() + ".png"); | |
} | |
} | |
} |
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-Java | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the cell which contains conditional formatting databar | |
Cell cell = worksheet.getCells().get("C1"); | |
// Create and get the conditional formatting of the worksheet | |
int idx = worksheet.getConditionalFormattings().add(); | |
FormatConditionCollection fcc = worksheet.getConditionalFormattings().get(idx); | |
fcc.addCondition(FormatConditionType.DATA_BAR); | |
fcc.addArea(CellArea.createCellArea("C1", "C4")); | |
// Access the conditional formatting databar | |
DataBar dbar = fcc.get(0).getDataBar(); | |
// Create image or print options | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setImageType(ImageType.PNG); | |
// Get the image bytes of the databar | |
byte[] imgBytes = dbar.toImage(cell, opts); | |
// Write image bytes on the disk | |
FileOutputStream out = new FileOutputStream(outputDir + "databar.png"); | |
out.write(imgBytes); | |
out.close(); | |
// save workbook with databars | |
workbook.save(outputDir + "databar.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(GenerateThumbnailofWorksheet.class) + "TechnicalArticles/"; | |
// Instantiate and open an Excel file | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the vertical and horizontal resolution | |
imgOptions.setVerticalResolution(200); | |
imgOptions.setHorizontalResolution(200); | |
// Set the image's format | |
imgOptions.setImageType(ImageType.JPEG); | |
// One page per sheet is enabled | |
imgOptions.setOnePagePerSheet(true); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
// Render the image for the sheet | |
sr.toImage(0, dataDir + "mythumb.jpg"); | |
// Creating Thumbnail | |
java.awt.Image img = ImageIO.read(new File(dataDir + "mythumb.jpg")).getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH); | |
BufferedImage img1 = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); | |
img1.createGraphics().drawImage( | |
ImageIO.read(new File(dataDir + "mythumb.jpg")).getScaledInstance(100, 100, img.SCALE_SMOOTH), 0, 0, null); | |
ImageIO.write(img1, "jpg", new File(dataDir + "GTOfWorksheet_out.jpg")); |
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-Java | |
//Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
//Output directory | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Create a workbook | |
Workbook workbook = new Workbook(sourceDir + "sampleUpdateActiveXComboBoxControl.xlsx"); | |
// Access first shape from first worksheet | |
Shape shape = workbook.getWorksheets().get(0).getShapes().get(0); | |
// Access ActiveX ComboBox Control and update its value | |
if (shape.getActiveXControl() != null) | |
{ | |
// Remove Shape ActiveX Control | |
shape.removeActiveXControl(); | |
} | |
// Save the workbook | |
workbook.save(outputDir + "RemoveActiveXControl_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(RemoveWhitespaceAroundData.class) + "TechnicalArticles/"; | |
// Instantiate a workbook | |
// Open the template file | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Specify your print area if you want | |
// sheet.PageSetup.PrintArea = "A1:H8"; | |
// To remove the white border around the image. | |
sheet.getPageSetup().setLeftMargin(0); | |
sheet.getPageSetup().setRightMargin(0); | |
sheet.getPageSetup().setTopMargin(0); | |
sheet.getPageSetup().setBottomMargin(0); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
imgOptions.setImageType(ImageType.EMF); | |
// Set only one page would be rendered for the image | |
imgOptions.setOnePagePerSheet(true); | |
imgOptions.setPrintingPage(PrintingPageType.IGNORE_BLANK); | |
// Create the SheetRender object based on the sheet with its | |
// ImageOrPrintOptions attributes | |
SheetRender render = new SheetRender(sheet, imgOptions); | |
// Convert the image | |
render.toImage(0, dataDir + "RWhitespaceAroundData_out.emf"); |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sampleRenderCustomDateFormat.xlsx"); | |
workbook.save(outDir + "sampleRenderCustomDateFormat_out.pdf"); |
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-Java | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(); | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
Cell cell = cells.get(0, 0); | |
cell.setArrayFormula("=MYFUNC()", 2, 2); | |
Style style = cell.getStyle(); | |
style.setNumber(14); | |
cell.setStyle(style); | |
CalculationOptions copt = new CalculationOptions(); | |
copt.setCustomEngine(new CustomFunctionStaticValue()); | |
workbook.calculateFormula(copt); | |
// Save to XLSX by setting the calc mode to manual | |
workbook.getSettings().setCalcMode(CalcModeType.MANUAL); | |
workbook.save(outputDir + "output.xlsx"); | |
// Save to PDF | |
workbook.save(outputDir + "output.pdf"); |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outDir = Utils.Get_OutputDirectory(); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the image file. | |
File file = new File(sourceDir + "background.png"); | |
// Get the picture into the streams. | |
byte[] imageData = new byte[(int) file.length()]; | |
FileInputStream fis = new FileInputStream(file); | |
fis.read(imageData); | |
// Set the background image for the sheet. | |
sheet.setBackgroundImage(imageData); | |
fis.close(); | |
// Save the excel file | |
workbook.save(outDir + "SBPforWorksheet.xlsx"); |
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-Java | |
// Instantiate the workbook from sample Excel file | |
Workbook workbook = new Workbook(srcDir + "sampleDataValidationRules.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
/* | |
* Access Cell C1. Cell C1 has the Decimal Validation applied on it.It can take only the values Between 10 and 20 | |
*/ | |
Cell cell = worksheet.getCells().get("C1"); | |
// Enter 3 inside this cell. Since it is not between 10 and 20, it should fail the validation | |
cell.putValue(3); | |
// Check if number 3 satisfies the Data Validation rule applied on this cell | |
System.out.println("Is 3 a Valid Value for this Cell: " + cell.getValidationValue()); | |
// Enter 15 inside this cell. Since it is between 10 and 20, it should succeed the validation | |
cell.putValue(15); | |
// Check if number 15 satisfies the Data Validation rule applied on this cell | |
System.out.println("Is 15 a Valid Value for this Cell: " + cell.getValidationValue()); | |
// Enter 30 inside this cell. Since it is not between 10 and 20, it should fail the validation again | |
cell.putValue(30); | |
// Check if number 30 satisfies the Data Validation rule applied on this cell | |
System.out.println("Is 30 a Valid Value for this Cell: " + cell.getValidationValue()); | |
// Enter large number 12345678901 inside this cell | |
// Since it is not between 1 and 999999999999, it should pass the validation again | |
Cell cell2 = worksheet.getCells().get("D1"); | |
cell2.putValue(12345678901l); | |
// Check if number 12345678901 satisfies the Data Validation rule applied on this cell | |
System.out.println("Is 12345678901 a Valid Value for this Cell: " + cell2.getValidationValue()); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(WorksheetToSeparateImage.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook object | |
// Open template | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Iterate over all worksheets in the workbook | |
for (int i = 0; i < book.getWorksheets().getCount(); i++) { | |
Worksheet sheet = book.getWorksheets().get(i); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Horizontal Resolution | |
options.setHorizontalResolution(300); | |
// Set Vertical Resolution | |
options.setVerticalResolution(300); | |
// Set Image Format | |
options.setImageType(ImageType.JPEG); | |
// If you want entire sheet as a single image | |
options.setOnePagePerSheet(true); | |
// Render to image | |
SheetRender sr = new SheetRender(sheet, options); | |
sr.toImage(0, dataDir + "WSheetToSImage_out-" + sheet.getName() + ".jpg"); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(WrapTextinCell.class) + "TechnicalArticles/"; | |
// Create Workbook Object | |
Workbook wb = new Workbook(); | |
// Open first Worksheet in the workbook | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Get Worksheet Cells Collection | |
Cells cell = ws.getCells(); | |
// Increase the width of First Column Width | |
cell.setColumnWidth(0, 35); | |
// Increase the height of first row | |
cell.setRowHeight(0, 65); | |
// Add Text to the First Cell | |
cell.get(0, 0).setValue("I am using the latest version of Aspose.Cells to test this functionality"); | |
// Get Cell's Style | |
Style style = cell.get(0, 0).getStyle(); | |
// Set Text Wrap property to true | |
style.setTextWrapped(true); | |
// Set Cell's Style | |
cell.get(0, 0).setStyle(style); | |
// Save Excel File | |
wb.save(dataDir + "WrapTextinCell_out.xls"); |
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-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "WebExtensionsSample.xlsx"); | |
WebExtensionTaskPaneCollection taskPanes = workbook.getWorksheets().getWebExtensionTaskPanes(); | |
for (Object obj : taskPanes) | |
{ | |
WebExtensionTaskPane taskPane = (WebExtensionTaskPane) obj; | |
System.out.println("Width: " + taskPane.getWidth()); | |
System.out.println("IsVisible: " + taskPane.isVisible()); | |
System.out.println("IsLocked: " + taskPane.isLocked()); | |
System.out.println("DockState: " + taskPane.getDockState()); | |
System.out.println("StoreName: " + taskPane.getWebExtension().getReference().getStoreName()); | |
System.out.println("StoreType: " + taskPane.getWebExtension().getReference().getStoreType()); | |
System.out.println("WebExtension.Id: " + taskPane.getWebExtension().getId()); | |
} |
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-Java | |
// The path to the output directory. | |
String outDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(); | |
WebExtensionCollection extensions = workbook.getWorksheets().getWebExtensions(); | |
WebExtensionTaskPaneCollection taskPanes = workbook.getWorksheets().getWebExtensionTaskPanes(); | |
int extensionIndex = extensions.add(); | |
int taskPaneIndex = taskPanes.add(); | |
WebExtension extension = extensions.get(extensionIndex); | |
extension.getReference().setId("wa104379955"); | |
extension.getReference().setStoreName("en-US"); | |
extension.getReference().setStoreType(WebExtensionStoreType.OMEX); | |
WebExtensionTaskPane taskPane = taskPanes.get(taskPaneIndex); | |
taskPane.setVisible(true); | |
taskPane.setDockState("right"); | |
taskPane.setWebExtension(extension); | |
workbook.save(outDir + "AddWebExtension_Out.xlsx"); |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "LargeSampleFile.xlsx"); | |
XlsbSaveOptions options = new XlsbSaveOptions(); | |
options.setCompressionType(OoxmlCompressionType.LEVEL_1); | |
long startTime = System.nanoTime(); | |
workbook.save(outDir + "LargeSampleFile_level_1_out.xlsb", options); | |
long endTime = System.nanoTime(); | |
long timeElapsed = endTime - startTime; | |
System.out.println("Level 1 Elapsed Time: " + timeElapsed / 1000000); | |
startTime = System.nanoTime(); | |
options.setCompressionType(OoxmlCompressionType.LEVEL_6); | |
workbook.save(outDir + "LargeSampleFile_level_6_out.xlsb", options); | |
endTime = System.nanoTime(); | |
timeElapsed = endTime - startTime; | |
System.out.println("Level 6 Elapsed Time: " + timeElapsed / 1000000); | |
startTime = System.nanoTime(); | |
options.setCompressionType(OoxmlCompressionType.LEVEL_9); | |
workbook.save(outDir + "LargeSampleFile_level_9_out.xlsb", options); | |
endTime = System.nanoTime(); | |
timeElapsed = endTime - startTime; | |
System.out.println("Level 9 Elapsed Time: " + timeElapsed / 1000000); |
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-Java | |
//directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Instantiating a WorkbookDesigner object | |
WorkbookDesigner designer = new WorkbookDesigner(); | |
Workbook workbook = new Workbook(sourceDir + "AllowLeadingApostropheSample.xlsx"); | |
workbook.getSettings().setQuotePrefixToStyle(false); | |
// Open a designer spreadsheet containing smart markers | |
designer.setWorkbook(workbook); | |
ArrayList<DataObject> list = new ArrayList<>(); | |
list.add(new DataObject(1, "demo")); | |
list.add(new DataObject(2, "'demo")); | |
// Set the data source for the designer spreadsheet | |
designer.setDataSource("sampleData", list); | |
// Process the smart markers | |
designer.process(); | |
designer.getWorkbook().save(outputDir + "AllowLeadingApostropheSample_out.xlsx"); |
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-Java | |
public static void main(String[] args) throws Exception { | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "LinkTypes.xlsx"); | |
// Get the first (default) worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Create a range A2:B3 | |
Range range = worksheet.getCells().createRange("A1", "A7"); | |
// Get Hyperlinks in range | |
Hyperlink[] hyperlinks = range.getHyperlinks(); | |
for (Hyperlink link : hyperlinks) | |
{ | |
System.out.println(link.getTextToDisplay() + ": " + getLinkTypeName(link.getLinkType())); | |
} | |
System.out.println("DetectLinkTypes executed successfully."); | |
} | |
private static String getLinkTypeName(int linkType){ | |
if(linkType == TargetModeType.EXTERNAL){ | |
return "EXTERNAL"; | |
} else if(linkType == TargetModeType.FILE_PATH){ | |
return "FILE_PATH"; | |
} else if(linkType == TargetModeType.EMAIL){ | |
return "EMAIL"; | |
} else { | |
return "CELL_REFERENCE"; | |
} | |
} |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "EmbeddedMolSample.xlsx"); | |
int index = 1; | |
for (Object obj : workbook.getWorksheets()) | |
{ | |
Worksheet sheet = (Worksheet)obj; | |
OleObjectCollection oles = sheet.getOleObjects(); | |
for (Object obj2 : oles) | |
{ | |
OleObject ole = (OleObject)obj2; | |
String fileName = outputDir + "OleObject" + index + ".mol "; | |
FileOutputStream fos = new FileOutputStream(fileName); | |
fos.write(ole.getObjectData()); | |
fos.flush(); | |
fos.close(); | |
index++; | |
} | |
} |
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-Java | |
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook(sourceDir + "HyperlinksSample.xlsx"); | |
// Get the first (default) worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Create a range A2:B3 | |
Range range = worksheet.getCells().createRange("A2", "B3"); | |
// Get Hyperlinks in range | |
Hyperlink[] hyperlinks = range.getHyperlinks(); | |
for (Hyperlink link : hyperlinks){ | |
System.out.println(link.getArea() + " : " + link.getAddress()); | |
// To delete the link, use the Hyperlink.Delete() method. | |
link.delete(); | |
} | |
workbook.save(outputDir + "HyperlinksSample_out.xlsx"); |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "ODataSample.xlsx"); | |
PowerQueryFormulaCollction PQFcoll = workbook.getDataMashup().getPowerQueryFormulas(); | |
for (Object obj : PQFcoll) | |
{ | |
PowerQueryFormula PQF = (PowerQueryFormula)obj; | |
System.out.println("Connection Name: " + PQF.getName()); | |
PowerQueryFormulaItemCollection PQFIcoll = PQF.getPowerQueryFormulaItems(); | |
for (Object obj2 : PQFIcoll) | |
{ | |
PowerQueryFormulaItem PQFI = (PowerQueryFormulaItem)obj2; | |
System.out.println("Name: " + PQFI.getName()); | |
System.out.println("Value: " + PQFI.getValue()); | |
} | |
} |
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-Java | |
// Instantiate a Workbook object and Open an Excel file | |
Workbook workbook = new Workbook(sourceDir + "SampleExternalReferences.xlsx"); | |
Name namedRange = workbook.getWorksheets().getNames().get("Names"); | |
// Get ReferredAreas | |
ReferredArea[] referredAreas = namedRange.getReferredAreas(true); | |
if (referredAreas != null) { | |
for (int i = 0; i < referredAreas.length; i++) { | |
ReferredArea referredArea = referredAreas[i]; | |
// Print the data in Referred Area | |
System.out.println("IsExternalLink: " + referredArea.isExternalLink()); | |
System.out.println("IsArea: " + referredArea.isArea()); | |
System.out.println("SheetName: " + referredArea.getSheetName()); | |
System.out.println("ExternalFileName: " + referredArea.getExternalFileName()); | |
System.out.println("StartColumn: " + referredArea.getStartColumn()); | |
System.out.println("StartRow: " + referredArea.getStartRow()); | |
System.out.println("EndColumn: " + referredArea.getEndColumn()); | |
System.out.println("EndRow: " + referredArea.getEndRow()); | |
} | |
} |
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-Java | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
WorkbookPrintingPreview preview = new WorkbookPrintingPreview(workbook, imgOptions); | |
System.out.println("Workbook page count: " + preview.getEvaluatedPageCount()); | |
SheetPrintingPreview preview2 = new SheetPrintingPreview(workbook.getWorksheets().get(0), imgOptions ); | |
System.out.println("Worksheet page count: " + preview2.getEvaluatedPageCount()); |
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-Java | |
// directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "SampleRegexReplace.xlsx"); | |
ReplaceOptions replace = new ReplaceOptions(); | |
replace.setCaseSensitive(false); | |
replace.setMatchEntireCellContents(false); | |
// Set to true to indicate that the searched key is regex | |
replace.setRegexKey(true); | |
workbook.replace("\\bKIM\\b", "^^^TIM^^^", replace); | |
workbook.save(outputDir + "RegexReplace_out.xlsx"); |
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-Java | |
public class StopConversionOrLoadingUsingInterruptMonitor | |
{ | |
static String outDir = Utils.Get_OutputDirectory(); | |
//Create InterruptMonitor object | |
InterruptMonitor im = new InterruptMonitor(); | |
public class ThreadStart extends Thread | |
{ | |
private int ThreadFunc; | |
public ThreadStart(int threadFunc) | |
{ | |
this.ThreadFunc = threadFunc; | |
} | |
//This function will create workbook and convert it to Pdf format | |
void CreateWorkbookAndConvertItToPdfFormat() throws Exception | |
{ | |
//Create a workbook object | |
Workbook wb = new Workbook(); | |
//Assign it InterruptMonitor object | |
wb.setInterruptMonitor(im); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access cell AB1000000 and add some text inside it. | |
Cell cell = ws.getCells().get("AB1000000"); | |
cell.putValue("This is text."); | |
try | |
{ | |
//Save the workbook to Pdf format | |
wb.save(outDir + "output_InterruptMonitor.pdf"); | |
//Show successful message | |
System.out.println("Excel to PDF - Successful Conversion"); | |
} | |
catch (CellsException ex) | |
{ | |
System.out.println("Process Interrupted - Message: " + ex.getMessage()); | |
} | |
} | |
//This function will interrupt the conversion process after 10s | |
void WaitForWhileAndThenInterrupt() throws Exception | |
{ | |
Thread.sleep(1000 * 10); | |
im.interrupt(); | |
} | |
public void run() | |
{ | |
try | |
{ | |
if(this.ThreadFunc == 1) | |
{ | |
CreateWorkbookAndConvertItToPdfFormat(); | |
} | |
if(this.ThreadFunc == 2) | |
{ | |
WaitForWhileAndThenInterrupt(); | |
} | |
} | |
catch(Exception ex) | |
{ | |
System.out.println("Process Interrupted - Message: " + ex.getMessage()); | |
} | |
} | |
}//ThreadStart | |
public void TestRun() throws Exception | |
{ | |
ThreadStart t1 = new ThreadStart(1); | |
ThreadStart t2 = new ThreadStart(2); | |
t1.start(); | |
t2.start(); | |
t1.join(); | |
t2.join(); | |
} | |
public static void main(String[] args) throws Exception { | |
new StopConversionOrLoadingUsingInterruptMonitor().TestRun(); | |
// Print the message | |
System.out.println("StopConversionOrLoadingUsingInterruptMonitor executed successfully."); | |
} | |
}//StopConversionOrLoadingUsingInterruptMonitor |
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-Java | |
// The path to the directories. | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(FileFormatType.XLSX); | |
int index = workbook.getContentTypeProperties().add("MK31", "Simple Data"); | |
workbook.getContentTypeProperties().get(index).setNillable(false); | |
index= workbook.getContentTypeProperties().add("MK32", "2019-10-17T16:00:00+00:00", "DateTime"); | |
workbook.getContentTypeProperties().get(index).setNillable(false); | |
workbook.save(outputDir + "WorkingWithContentTypeProperties_out.xlsx"); |
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-Java | |
// directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sourceFile.xlsx"); | |
String password = "pfxPassword"; | |
String pfx = "pfxFile"; | |
// Load the certificate into an instance of InputStream | |
InputStream inStream = new FileInputStream(pfx); | |
// Create an instance of KeyStore with PKCS12 cryptography | |
java.security.KeyStore inputKeyStore = java.security.KeyStore.getInstance("PKCS12"); | |
// Use the KeyStore.load method to load the certificate stream and its password | |
inputKeyStore.load(inStream, password.toCharArray()); | |
DigitalSignature signature = new DigitalSignature(inputKeyStore, password, "testXAdES", com.aspose.cells.DateTime.getNow()); | |
signature.setXAdESType(XAdESType.X_AD_ES); | |
DigitalSignatureCollection dsCollection = new DigitalSignatureCollection(); | |
dsCollection.add(signature); | |
workbook.setDigitalSignature(dsCollection); | |
workbook.save(outputDir + "XAdESSignatureSupport_out.xlsx"); |
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-Java | |
//Implementation of IStreamProvider | |
class SP implements IStreamProvider | |
{ | |
public void closeStream(StreamProviderOptions arg0) throws Exception { | |
} | |
public void initStream(StreamProviderOptions options) throws Exception { | |
//Open the filestream of Aspose Logo and assign it to StreamProviderOptions.Stream property | |
File imgFile = new File(srcDir + "sampleControlExternalResourcesUsingWorkbookSetting_StreamProvider.png"); | |
byte[] bts = new byte[(int) imgFile.length()]; | |
FileInputStream fin = new FileInputStream(imgFile); | |
fin.read(bts); | |
fin.close(); | |
ByteArrayOutputStream baout = new ByteArrayOutputStream(); | |
baout.write(bts); | |
baout.close(); | |
options.setStream(baout); | |
} | |
} | |
public void Run() throws Exception { | |
System.out.println("Aspose.Cells for Java Version: " + CellsHelper.getVersion()); | |
//String srcDir = Utils.Get_SourceDirectory(); | |
//String outDir = Utils.Get_OutputDirectory(); | |
//Load sample Excel file containing the external resource e.g. linked image etc. | |
Workbook wb = new Workbook(srcDir + "sampleControlExternalResourcesUsingWorkbookSetting_StreamProvider.xlsx"); | |
//Provide your implementation of IStreamProvider | |
wb.getSettings().setStreamProvider(new SP()); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Specify image or print options, we need one page per sheet and png output | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setImageType(ImageType.PNG); | |
//Create sheet render by passing required parameters | |
SheetRender sr = new SheetRender(ws, opts); | |
//Convert your entire worksheet into png image | |
sr.toImage(0, outDir + "outputControlExternalResourcesUsingWorkbookSettingStreamProvider.png"); | |
// Print the message | |
System.out.println("ControlExternalResourcesUsingWorkbookSetting_StreamProvider executed successfully."); | |
} | |
public static void main(String[] args) throws Exception { | |
new ControlExternalResourcesUsingWorkbookSetting_StreamProvider().Run(); | |
} |
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-Java | |
// Define variables | |
String name = "HasFormula"; | |
String value = "=GET.CELL(48, INDIRECT(\"ZS\",FALSE))"; | |
// Load the template file | |
Workbook wbSource = new Workbook(srcDir + "sampleNamedRangeTest.xlsm"); | |
// Get the worksheets collection | |
WorksheetCollection wsCol = wbSource.getWorksheets(); | |
// Add new name to the names collection | |
int nameIndex = wsCol.getNames().add(name); | |
// Set value to the named range | |
Name namedRange = wsCol.getNames().get(nameIndex); | |
namedRange.setRefersTo(value); | |
// Save the output file | |
wbSource.save(outDir + "sampleOutputNamedRangeTest.xlsm"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Add Author | |
int authorIndex = workbook.getWorksheets().getThreadedCommentAuthors().add("Aspose Test", "", ""); | |
ThreadedCommentAuthor author = workbook.getWorksheets().getThreadedCommentAuthors().get(authorIndex); | |
// Add Threaded Comment | |
workbook.getWorksheets().get(0).getComments().addThreadedComment("A1", "Test Threaded Comment", author); | |
workbook.save(dataDir + "AddThreadedComments_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/"; | |
//Load source Excel file | |
Workbook workbook = new Workbook(dataDir + "BookWithSomeData.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Print number of cells in the Worksheet | |
System.out.println("Number of Cells: " + worksheet.getCells().getCount()); | |
// If the number of cells is greater than 2147483647, use CountLarge | |
System.out.println("Number of Cells (CountLarge): " + worksheet.getCells().getCountLarge()); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
worksheet.getCells().get(0, 2).setValue(1); | |
worksheet.getCells().get(1, 2).setValue(2); | |
worksheet.getCells().get(2, 2).setValue(3); | |
worksheet.getCells().get(2, 3).setValue(4); | |
worksheet.getCells().createRange(0, 2, 3, 1).setName("NamedRange"); | |
Range cut = worksheet.getCells().createRange("C:C"); | |
worksheet.getCells().insertCutCells(cut, 0, 1, ShiftType.RIGHT); | |
workbook.save(dataDir + "CutAndPasteCells.xlsx"); |
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-Java | |
// The path to the Source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
//Load source Excel file | |
Workbook workbook = new Workbook(sourceDir + "InternationalMacroSheet.xlsm"); | |
//Get Sheet Type | |
int sheetType = workbook.getWorksheets().get(0).getType(); | |
//Print Sheet Type | |
if(sheetType == SheetType.INTERNATIONAL_MACRO) { | |
System.out.println("Sheet Type: INTERNATIONAL_MACRO"); | |
} else { | |
System.out.println("Sheet Type: Other"); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get Threaded Comment | |
ThreadedComment comment = worksheet.getComments().getThreadedComments("A1").get(0); | |
comment.setNotes("Updated Comment"); | |
workbook.save(dataDir + "EditThreadedComments.xlsx"); |
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-Java | |
//directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(sourceDir + "SampleBook1.ods"); | |
// Add a page break at cell Y30 | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
Cell cell = worksheet.getCells().get("A9"); | |
if(cell.getValidation() != null) | |
{ | |
System.out.println(cell.getValidation().getType()); | |
} |
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-Java | |
//Source directory | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// Load source Excel file | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Print Unique Id | |
System.out.println("Unique Id: " + worksheet.getUniqueId()); |
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-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; | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ReadThreadedCommentCreatedTime.class) + "Worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get Threaded Comments | |
ThreadedCommentCollection threadedComments = worksheet.getComments().getThreadedComments("A1"); | |
for (Object obj : threadedComments) | |
{ | |
ThreadedComment comment = (ThreadedComment) obj; | |
System.out.println("Comment: " + comment.getNotes()); | |
System.out.println("Author: " + comment.getAuthor().getName()); | |
System.out.println("Created Time: " + comment.getCreatedTime()); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get Threaded Comments | |
ThreadedCommentCollection threadedComments = worksheet.getComments().getThreadedComments("A1"); | |
for (Object obj : threadedComments) | |
{ | |
ThreadedComment comment = (ThreadedComment) obj; | |
System.out.println("Comment: " + comment.getNotes()); | |
System.out.println("Author: " + comment.getAuthor().getName()); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "ThreadedCommentsSample.xlsx"); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
CommentCollection comments = worksheet.getComments(); | |
ThreadedCommentCollection threadedComments = worksheet.getComments().getThreadedComments("I4"); | |
ThreadedCommentAuthor author = threadedComments.get(0).getAuthor(); | |
comments.removeAt("I4"); | |
ThreadedCommentAuthorCollection authors = workbook.getWorksheets().getThreadedCommentAuthors(); | |
authors.removeAt(authors.indexOf(author)); | |
workbook.save(dataDir + "ThreadedCommentsSample_Out.xlsx"); |
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-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); |
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-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); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveFileInExcel972003format.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in Excel2003 format | |
workbook.save(dataDir + "output.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveInExcel2007xlsbFormat.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in Excel2007 xlsb format | |
workbook.save(dataDir + "output.xlsb", FileFormatType.XLSB); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveInExcel2007xlsxFormat.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in Excel2007 xlsx format | |
workbook.save(dataDir + "output.xlsx", FileFormatType.XLSX); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveInHtmlFormat.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in SpreadsheetML format | |
workbook.save(dataDir + "output.html", FileFormatType.HTML); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveInODSFormat.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in ODS format | |
workbook.save(dataDir + "output.ods", FileFormatType.ODS); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveInPdfFormat.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in PDF format | |
workbook.save(dataDir + "output.pdf", FileFormatType.PDF); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveInSpreadsheetMLFormat.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in SpreadsheetML format | |
workbook.save(dataDir + "output.xml", FileFormatType.EXCEL_2003_XML); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveWorkbookToTextCSVFormat.class); | |
// Load your source workbook | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// 0-byte array | |
byte[] workbookData = new byte[0]; | |
// Text save options. You can use any type of separator | |
TxtSaveOptions opts = new TxtSaveOptions(); | |
opts.setSeparator('\t'); | |
// Copy each worksheet data in text format inside workbook data array | |
for (int idx = 0; idx < workbook.getWorksheets().getCount(); idx++) { | |
// Save the active worksheet into text format | |
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | |
workbook.getWorksheets().setActiveSheetIndex(idx); | |
workbook.save(bout, opts); | |
// Save the worksheet data into sheet data array | |
byte[] sheetData = bout.toByteArray(); | |
// Combine this worksheet data into workbook data array | |
byte[] combinedArray = new byte[workbookData.length + sheetData.length]; | |
System.arraycopy(workbookData, 0, combinedArray, 0, workbookData.length); | |
System.arraycopy(sheetData, 0, combinedArray, workbookData.length, sheetData.length); | |
workbookData = combinedArray; | |
} | |
// Save entire workbook data into file | |
FileOutputStream fout = new FileOutputStream(dataDir + "data.out.txt"); | |
fout.write(workbookData); | |
fout.close(); | |
// Print message | |
System.out.println("Excel to Text File Conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveXLSFile.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in xls format | |
workbook.save(dataDir + "output.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveXLSXFile.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in xlsx format | |
workbook.save(dataDir + "output.xlsx", FileFormatType.XLSX); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SavingFiles.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(dataDir + "book.xls"); | |
// Save in default (Excel2003) format | |
workbook.save(dataDir + "book.default.out.xls"); | |
// Save in Excel2003 format | |
workbook.save(dataDir + "book.out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Save in Excel2007 xlsx format | |
workbook.save(dataDir + "book.out.xlsx", FileFormatType.XLSX); | |
// Save in SpreadsheetML format | |
workbook.save(dataDir + "book.out.xml", FileFormatType.EXCEL_2003_XML); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SavingFiletoSomeLocation.class); | |
String filePath = dataDir + "Book1.xls"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(filePath); | |
// Save in Excel 97 – 2003 format | |
workbook.save(dataDir + ".output.xls"); | |
// OR workbook.save(dataDir + ".output..xls", new XlsSaveOptions(SaveFormat.Excel97To2003)); | |
// Save in Excel2007 xlsx format | |
workbook.save(dataDir + ".output.xlsx", FileFormatType.XLSX); | |
// Save in Excel2007 xlsb format | |
workbook.save(dataDir + ".output.xlsb", FileFormatType.XLSB); | |
// Save in ODS format | |
workbook.save(dataDir + ".output.ods", FileFormatType.ODS); | |
// Save in Pdf format | |
workbook.save(dataDir + ".output.pdf", FileFormatType.PDF); | |
// Save in Html format | |
workbook.save(dataDir + ".output.html", FileFormatType.HTML); | |
// Save in SpreadsheetML format | |
workbook.save(dataDir + ".output.xml", FileFormatType.EXCEL_2003_XML); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SavingFiletoStream.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
FileOutputStream stream = new FileOutputStream(dataDir + "output.xlsx"); | |
workbook.save(stream, new XpsSaveOptions(FileFormatType.XLSX)); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); | |
stream.close(); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SavingTextFilewithCustomSeparator.class); | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
TxtSaveOptions toptions = new TxtSaveOptions(); | |
// Specify the separator | |
toptions.setSeparator(';'); | |
workbook.save(dataDir + "output.csv"); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AdvancedConversiontoPdf.class); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
Cells cell = workbook.getWorksheets().get(0).getCells(); | |
cell.get("A12").setValue("Test PDF"); | |
PdfSaveOptions pdfOptions = new PdfSaveOptions(); | |
pdfOptions.setCompliance(PdfCompliance.PDF_A_1_B); | |
workbook.save(dataDir + "output2.pdf", pdfOptions); | |
// Print message | |
System.out.println("Advanced Conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChartToImage.class); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Set the name of worksheet | |
sheet.setName("Data"); | |
// Get the cells collection in the sheet. | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// Put some values into a cells of the Data sheet. | |
cells.get("A1").setValue("Region"); | |
cells.get("A2").setValue("France"); | |
cells.get("A3").setValue("Germany"); | |
cells.get("A4").setValue("England"); | |
cells.get("A5").setValue("Sweden"); | |
cells.get("A6").setValue("Italy"); | |
cells.get("A7").setValue("Spain"); | |
cells.get("A8").setValue("Portugal"); | |
cells.get("B1").setValue("Sale"); | |
cells.get("B2").setValue(70000); | |
cells.get("B3").setValue(55000); | |
cells.get("B4").setValue(30000); | |
cells.get("B5").setValue(40000); | |
cells.get("B6").setValue(35000); | |
cells.get("B7").setValue(32000); | |
cells.get("B8").setValue(10000); | |
// Create chart | |
int chartIndex = sheet.getCharts().add(ChartType.COLUMN, 12, 1, 33, 12); | |
Chart chart = sheet.getCharts().get(chartIndex); | |
// Set properties of chart title | |
chart.getTitle().setText("Sales By Region"); | |
chart.getTitle().getFont().setBold(true); | |
chart.getTitle().getFont().setSize(12); | |
// Set properties of nseries | |
chart.getNSeries().add("Data!B2:B8", true); | |
chart.getNSeries().setCategoryData("Data!A2:A8"); | |
// Set the fill colors for the series's data points (France - Portugal(7 points)) | |
ChartPointCollection chartPoints = chart.getNSeries().get(0).getPoints(); | |
ChartPoint point = chartPoints.get(0); | |
point.getArea().setForegroundColor(Color.getCyan()); | |
point = chartPoints.get(1); | |
point.getArea().setForegroundColor(Color.getBlue()); | |
point = chartPoints.get(2); | |
point.getArea().setForegroundColor(Color.getYellow()); | |
point = chartPoints.get(3); | |
point.getArea().setForegroundColor(Color.getRed()); | |
point = chartPoints.get(4); | |
point.getArea().setForegroundColor(Color.getBlack()); | |
point = chartPoints.get(5); | |
point.getArea().setForegroundColor(Color.getGreen()); | |
point = chartPoints.get(6); | |
point.getArea().setForegroundColor(Color.getMaroon()); | |
// Set the legend invisible | |
chart.setShowLegend(false); | |
// Get the Chart image | |
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions(); | |
imgOpts.setImageFormat(ImageFormat.getEmf()); | |
FileOutputStream fs = new FileOutputStream(dataDir + "output.emf"); | |
// Save the chart image file. | |
chart.toImage(fs, imgOpts); | |
fs.close(); | |
// Print message | |
System.out.println("Processing performed successfully."); |
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-Java | |
String dataDir = Utils.getDataDir(ConvertChartToPdf.class); | |
String inputPath = dataDir + "Sample1.xls"; | |
String outputPath = dataDir + "Output.pdf"; | |
// Load excel file containing charts | |
Workbook workbook = new Workbook(inputPath); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first chart inside the worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Save the chart into pdf format | |
chart.toPdf(outputPath); | |
System.out.println("File saved " + outputPath); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingToHTMLFiles.class); | |
// Specify the file path | |
String filePath = dataDir + "Book1.xlsx"; | |
// Specify the HTML saving options | |
HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.M_HTML); | |
// Instantiate a workbook and open the template XLSX file | |
Workbook wb = new Workbook(filePath); | |
// Save the HTML file | |
wb.save(dataDir + "output.html", sv); | |
// Print message | |
System.out.println("Excel to HTML conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingToMHTMLFiles.class); | |
// Specify the file path | |
String filePath = dataDir + "Book1.xlsx"; | |
// Specify the HTML saving options | |
HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.M_HTML); | |
// Instantiate a workbook and open the template XLSX file | |
Workbook wb = new Workbook(filePath); | |
// Save the MHT file | |
wb.save(dataDir + "output.mht", sv); | |
// Print message | |
System.out.println("Excel to MHTML conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingToXPS.class); | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Apply different Image and Print options | |
com.aspose.cells.ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set the Format | |
options.setSaveFormat(SaveFormat.XPS); | |
// Render the sheet with respect to specified printing options | |
com.aspose.cells.SheetRender sr = new SheetRender(sheet, options); | |
sr.toImage(0, dataDir + "output.xps"); | |
// Save the complete Workbook in XPS format | |
workbook.save(dataDir + "output.xps", SaveFormat.XPS); | |
// Print message | |
System.out.println("Excel to XPS conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingWorksheetToSVG.class); | |
String path = dataDir + "Template.xlsx"; | |
// Create a workbook object from the template file | |
Workbook workbook = new Workbook(path); | |
// Convert each worksheet into svg format in a single page. | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
imgOptions.setSaveFormat(SaveFormat.SVG); | |
imgOptions.setOnePagePerSheet(true); | |
// Convert each worksheet into svg format | |
int sheetCount = workbook.getWorksheets().getCount(); | |
for (int i = 0; i < sheetCount; i++) { | |
Worksheet sheet = workbook.getWorksheets().get(i); | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int k = 0; k < sr.getPageCount(); k++) { | |
// Output the worksheet into Svg image format | |
sr.toImage(k, path + sheet.getName() + k + ".output.svg"); | |
} | |
} | |
// Print message | |
System.out.println("Excel to SVG conversion completed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(EncryptingFiles.class); | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Password protect the file. | |
workbook.getSettings().setPassword("1234"); | |
// Specify XOR encrption type. | |
workbook.setEncryptionOptions(EncryptionType.XOR, 40); | |
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider). | |
workbook.setEncryptionOptions(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128); | |
// Save the excel file. | |
workbook.save(dataDir + "output.xls"); | |
// Print message | |
System.out.println("Encryption applied successfully on output file."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Excel2PDFConversion.class); | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Save the document in PDF format | |
workbook.save(dataDir + "output.pdf", SaveFormat.PDF); | |
// Print message | |
System.out.println("Excel to PDF conversion performed successfully."); |
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-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(ExpandTextFromRightToLeftWhileExportingExcelFileToHTML.class) + "Conversion/"; | |
//Load source excel file inside the workbook object | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
//Save workbook in HTML format | |
wb.save(dataDir + "output-" + CellsHelper.getVersion() + ".html", SaveFormat.HTML); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExportWholeWorkbooktoXPS.class); | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set the format | |
options.setSaveFormat(SaveFormat.XPS); | |
// Render the workbook with respect to specified printing options | |
WorkbookRender render = new WorkbookRender(workbook, options); | |
render.toImage(dataDir + "output.xps"); | |
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-Java | |
// The path to the resource directory. | |
String dataDir = Utils.getSharedDataDir(IsPivotTableCompatibleForExcel2003.class) + "Conversion/"; | |
//Load source excel file containing sample pivot table | |
Workbook wb = new Workbook(dataDir + "sample-pivot-table.xlsx"); | |
//Access first worksheet that contains pivot table data | |
Worksheet dataSheet = wb.getWorksheets().get(0); | |
//Access cell A3 and sets its data | |
Cells cells = dataSheet.getCells(); | |
Cell cell = cells.get("A3"); | |
cell.putValue("FooBar"); | |
//Access cell B3 and sets its data | |
//We set B3 a very long string which has more than 255 characters | |
String longStr = "Very long text 1. very long text 2. very long text 3. very long text 4. very long text 5. very long text 6. very long text 7. very long text 8. very long text 9. very long text 10. very long text 11. very long text 12. very long text 13. very long text 14. very long text 15. very long text 16. very long text 17. very long text 18. very long text 19. very long text 20. End of text."; | |
cell = cells.get("B3"); | |
cell.putValue(longStr); | |
//Print the length of cell B3 string | |
System.out.println("Length of original data string: " + cell.getStringValue().length()); | |
//Access cell C3 and sets its data | |
cell = cells.get("C3"); | |
cell.putValue("closed"); | |
//Access cell D3 and sets its data | |
cell = cells.get("D3"); | |
cell.putValue("2016/07/21"); | |
//Access the second worksheet that contains pivot table | |
Worksheet pivotSheet = wb.getWorksheets().get(1); | |
//Access the pivot table | |
PivotTable pivotTable = pivotSheet.getPivotTables().get(0); | |
//IsExcel2003Compatible property tells if PivotTable is compatible for Excel2003 while refreshing PivotTable. | |
//If it is true, a string must be less than or equal to 255 characters, so if the string is greater than 255 characters, | |
//it will be truncated. If false, a string will not have the aforementioned restriction. | |
//The default value is true. | |
pivotTable.setExcel2003Compatible(true); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
//Check the value of cell B5 of pivot sheet. | |
//It will be 255 because we have set IsExcel2003Compatible property to true | |
//All the data after 255 characters has been truncated | |
Cell b5 = pivotSheet.getCells().get("B5"); | |
System.out.println("Length of cell B5 after setting IsExcel2003Compatible property to True: " + b5.getStringValue().length()); | |
//Now set IsExcel2003Compatible property to false and again refresh | |
pivotTable.setExcel2003Compatible(false); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
//Now it will print 383 the original length of cell data | |
//The data has not been truncated now. | |
b5 = pivotSheet.getCells().get("B5"); | |
System.out.println("Length of cell B5 after setting IsExcel2003Compatible property to False: " + b5.getStringValue().length()); | |
//Set the row height and column width of cell B5 and also wrap its text | |
pivotSheet.getCells().setRowHeight(b5.getRow(), 100); | |
pivotSheet.getCells().setColumnWidth(b5.getColumn(), 65); | |
Style st = b5.getStyle(); | |
st.setTextWrapped(true); | |
b5.setStyle(st); | |
//Save workbook in xlsx format | |
wb.save(dataDir + "output.xlsx", SaveFormat.XLSX); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ManagingDocumentProperties.class); | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Retrieve a list of all custom document properties of the Excel file | |
CustomDocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties(); | |
// Accessing a custom document property by using the property index | |
DocumentProperty customProperty1 = customProperties.get(3); | |
// Accessing a custom document property by using the property name | |
DocumentProperty customProperty2 = customProperties.get("Owner"); | |
// Adding a custom document property to the Excel file | |
DocumentProperty publisher = customProperties.add("Publisher", "Aspose"); | |
// Save the file | |
workbook.save(dataDir + "output.xls"); | |
// Removing a custom document property | |
customProperties.remove("Publisher"); | |
// Save the file | |
workbook.save(dataDir + "output.xls"); | |
// Print message | |
System.out.println("Excel file's custom properties accessed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(QuickExceltoXPSConversion.class); | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Save in XPS format | |
workbook.save(dataDir + "output.xps", SaveFormat.XPS); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RenderUnicodeSupplementarycharactersinoutputPdf.class); | |
// Load your source excel file containing Unicode Supplementary | |
// characters | |
Workbook wb = new Workbook(dataDir + "unicode-supplementary-characters.xlsx"); | |
// Save the workbook | |
wb.save(dataDir + "output.pdf"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RenderUnicodeSupplementarycharactersinoutputPdf.class); | |
// Load your source excel file containing Unicode Supplementary | |
// characters | |
Workbook wb = new Workbook(dataDir + "unicode-supplementary-characters.xlsx"); | |
// Save the workbook | |
wb.save(dataDir + "output.pdf"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RenderUnicodeSupplimentaryCharacterToPDF.class); | |
// Load your source excel file containing Unicode Supplementary | |
// characters | |
Workbook wb = new Workbook(dataDir + "unicode-supplementary-characters.xlsx"); | |
// Save the workbook | |
wb.save(dataDir + "output.pdf"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RenderUnicodeSupplimentaryCharacterToPDF.class); | |
// Load your source excel file containing Unicode Supplementary | |
// characters | |
Workbook wb = new Workbook(dataDir + "unicode-supplementary-characters.xlsx"); | |
// Save the workbook | |
wb.save(dataDir + "output.pdf"); |
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-Java | |
// Directory path where output HTML files are to be saved | |
String dataDir = Utils.getSharedDataDir(SetDefaultFontWhileRenderingSpreadsheetToHTML.class) + "Conversion/"; | |
//Create workbook object. | |
Workbook wb = new Workbook(); | |
//Access first WorkSheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access cell B4 and add some text inside it. | |
Cell cell = ws.getCells().get("B4"); | |
cell.putValue("This text has some unknown or invalid font which does not exist."); | |
//Set the font of cell B4 which is unknown. | |
Style st = cell.getStyle(); | |
st.getFont().setName("UnknownNotExist"); | |
st.getFont().setSize(20); | |
cell.setStyle(st); | |
//Now save the workbook in html format and set the default font to Courier New. | |
HtmlSaveOptions opts = new HtmlSaveOptions(); | |
opts.setDefaultFontName("Courier New"); | |
wb.save(dataDir + "out_courier_new.htm", opts); | |
//Now save the workbook in html format once again but set the default font to Arial. | |
opts.setDefaultFontName("Arial"); | |
wb.save(dataDir + "out_arial.htm", opts); | |
//Now save the workbook in html format once again but set the default font to Times New Roman. | |
opts.setDefaultFontName("Times New Roman"); | |
wb.save(dataDir + "out_times_new_roman.htm", opts); |
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-Java | |
// Directory path where output HTML files are to be saved | |
String dataDir = Utils.getSharedDataDir(SetDefaultFontWhileRenderingSpreadsheetToImages.class) + "Conversion/"; | |
//Create workbook object. | |
Workbook wb = new Workbook(); | |
//Set default font of the workbook to none | |
Style s = wb.getDefaultStyle(); | |
s.getFont().setName(""); | |
wb.setDefaultStyle(s); | |
//Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access cell A4 and add some text inside it. | |
Cell cell = ws.getCells().get("A4"); | |
cell.putValue("This text has some unknown or invalid font which does not exist."); | |
//Set the font of cell A4 which is unknown. | |
Style st = cell.getStyle(); | |
st.getFont().setName("UnknownNotExist"); | |
st.getFont().setSize(20); | |
st.setTextWrapped(true); | |
cell.setStyle(st); | |
//Set first column width and fourth column height | |
ws.getCells().setColumnWidth(0, 80); | |
ws.getCells().setRowHeight(3, 60); | |
//Create image or print options. | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setImageFormat(ImageFormat.getPng()); | |
//Render worksheet image with Courier New as default font. | |
opts.setDefaultFont("Courier New"); | |
SheetRender sr = new SheetRender(ws, opts); | |
sr.toImage(0, dataDir + "out_courier_new.png"); | |
//Render worksheet image again with Times New Roman as default font. | |
opts.setDefaultFont("Times New Roman"); | |
sr = new SheetRender(ws, opts); | |
sr.toImage(0, dataDir + "out_times_new_roman.png"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetPDFCreationTime.class); | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Create an instance of PdfSaveOptions and pass SaveFormat to the constructor | |
PdfSaveOptions options = new PdfSaveOptions(FileFormatType.PDF); | |
options.setCreatedTime(DateTime.getNow()); | |
// Save the file | |
workbook.save(dataDir + "output.pdf", options); | |
// Print message | |
System.out.println("Set PDF Creation Time successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingImagePrefrencesforHTML.class); | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
System.out.println("Set PDF Creation Time successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(WorksheetToImage.class); | |
// Instantiate a new workbook with path to an Excel file | |
Workbook book = new Workbook(dataDir + "MyTestBook1.xls"); | |
// Create an object for ImageOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the image type | |
imgOptions.setImageFormat(ImageFormat.getPng()); | |
// Get the first worksheet. | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Create a SheetRender object for the target sheet | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int j = 0; j < sr.getPageCount(); j++) { | |
// Generate an image for the worksheet | |
sr.toImage(j, dataDir + "output" + j + ".png"); | |
} | |
// Print message | |
System.out.println("Images generated successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(XlstoPDFDirectConversation.class); | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Save the file | |
workbook.save(dataDir + "output.pdf"); | |
// Print message | |
System.out.println("Converted xls to Pdf successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ApplyGradientFillEffects.class); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet (default) in the workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Input a value into B3 cell | |
worksheet.getCells().get(2, 1).putValue("test"); | |
// Get the Style of the cell | |
Style style = worksheet.getCells().get("B3").getStyle(); | |
// Set Gradient pattern on | |
style.setGradient(true); | |
// Specify two color gradient fill effects | |
style.setTwoColorGradient(Color.fromArgb(255, 255, 255), Color.fromArgb(79, 129, 189), | |
GradientStyleType.HORIZONTAL, 1); | |
// Set the color of the text in the cell | |
style.getFont().setColor(Color.getRed()); | |
// Specify horizontal and vertical alignment settings | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
style.setVerticalAlignment(TextAlignmentType.CENTER); | |
// Apply the style to the cell | |
worksheet.getCells().get("B3").setStyle(style); | |
// Set the third row height in pixels | |
worksheet.getCells().setRowHeightPixel(2, 53); | |
// Merge the range of cells (B3:C3) | |
worksheet.getCells().merge(2, 1, 1, 2); | |
// Save the Excel file | |
workbook.save(dataDir + "Book1.xlsx"); |
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-Java | |
// Path to source file | |
String dataDir = Utils.getDataDir(ConditionalFormattingatRuntime.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
ConditionalFormattingCollection cfs = sheet.getConditionalFormattings(); | |
// The first method:adds an empty conditional formatting | |
int index = cfs.add(); | |
FormatConditionCollection fcs = cfs.get(index); | |
// Sets the conditional format range. | |
CellArea ca1 = new CellArea(); | |
ca1.StartRow = 0; | |
ca1.StartColumn = 0; | |
ca1.EndRow = 0; | |
ca1.EndColumn = 0; | |
CellArea ca2 = new CellArea(); | |
ca2.StartRow = 0; | |
ca2.StartColumn = 0; | |
ca2.EndRow = 0; | |
ca2.EndColumn = 0; | |
CellArea ca3 = new CellArea(); | |
ca3.StartRow = 0; | |
ca3.StartColumn = 0; | |
ca3.EndRow = 0; | |
ca3.EndColumn = 0; | |
fcs.addArea(ca1); | |
fcs.addArea(ca2); | |
fcs.addArea(ca3); | |
// Sets condition formulas. | |
int conditionIndex = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "=A2", "100"); | |
FormatCondition fc = fcs.get(conditionIndex); | |
int conditionIndex2 = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100"); | |
// Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingARow.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Adding a new Style to the styles collection of the Excel object Accessing the newly added Style to the Excel object | |
Style style = workbook.createStyle(); | |
// Setting the vertical alignment of the text in the cell | |
style.setVerticalAlignment(TextAlignmentType.CENTER); | |
// Setting the horizontal alignment of the text in the cell | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
// Setting the font color of the text in the cell | |
Font font = style.getFont(); | |
font.setColor(Color.getGreen()); | |
// Shrinking the text to fit in the cell | |
style.setShrinkToFit(true); | |
// Setting the bottom border of the cell | |
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.getRed()); | |
// Creating StyleFlag | |
StyleFlag styleFlag = new StyleFlag(); | |
styleFlag.setHorizontalAlignment(true); | |
styleFlag.setVerticalAlignment(true); | |
styleFlag.setShrinkToFit(true); | |
styleFlag.setBottomBorder(true); | |
styleFlag.setFontColor(true); | |
// Accessing a column from the Columns collection | |
Column column = cells.getColumns().get(0); | |
// Applying the style to the column | |
column.applyStyle(style, styleFlag); | |
// Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingARow.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Adding a new Style to the styles collection of the Excel object Accessing the newly added Style to the Excel object | |
Style style = workbook.createStyle(); | |
// Setting the vertical alignment of the text in the cell | |
style.setVerticalAlignment(TextAlignmentType.CENTER); | |
// Setting the horizontal alignment of the text in the cell | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
// Setting the font color of the text in the cell | |
Font font = style.getFont(); | |
font.setColor(Color.getGreen()); | |
// Shrinking the text to fit in the cell | |
style.setShrinkToFit(true); | |
// Setting the bottom border of the cell | |
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.getRed()); | |
// Creating StyleFlag | |
StyleFlag styleFlag = new StyleFlag(); | |
styleFlag.setHorizontalAlignment(true); | |
styleFlag.setVerticalAlignment(true); | |
styleFlag.setShrinkToFit(true); | |
styleFlag.setBottomBorder(true); | |
styleFlag.setFontColor(true); | |
// Accessing a row from the Rows collection | |
Row row = cells.getRows().get(0); | |
// Assigning the Style object to the Style property of the row | |
row.applyStyle(style, styleFlag); | |
// Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingCellsUsingsetStyleMethod.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = cells.get("A1"); | |
// Adding some value to the "A1" cell | |
cell.setValue("Hello Aspose!"); | |
Style style = cell.getStyle(); | |
// Setting the vertical alignment of the text in the "A1" cell | |
style.setVerticalAlignment(TextAlignmentType.CENTER); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
// Setting the font color of the text in the "A1" cell | |
Font font = style.getFont(); | |
font.setColor(Color.getGreen()); | |
// Setting the cell to shrink according to the text contained in it | |
style.setShrinkToFit(true); | |
// Setting the bottom border | |
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.getRed()); | |
// Saved style | |
cell.setStyle(style); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingCellsUsingStyleObject.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = cells.get("A1"); | |
// Adding some value to the "A1" cell | |
cell.setValue("Hello Aspose!"); | |
// Adding a new Style to the styles collection of the Excel object | |
Style style = workbook.createStyle(); | |
// Setting the vertical alignment of the text in the "A1" cell | |
style.setVerticalAlignment(TextAlignmentType.CENTER); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
// Setting the font color of the text in the "A1" cell | |
Font font = style.getFont(); | |
font.setColor(Color.getGreen()); | |
// Setting the cell to shrink according to the text contained in it | |
style.setShrinkToFit(true); | |
// Setting the bottom border | |
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.getRed()); | |
// Saved style | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingSelectedCharacters.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Visit Aspose!"); | |
Font font = cell.characters(6, 7).getFont(); | |
// Setting the font of selected characters to bold | |
font.setBold(true); | |
// Setting the font color of selected characters to blue | |
font.setColor(Color.getBlue()); | |
// Saving the Excel file | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Indentation.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Setting the vertical alignment of the text in a cell | |
Style style1 = cell.getStyle(); | |
style1.setIndentLevel(2); | |
cell.setStyle(style1); | |
// Saved style | |
cell.setStyle(style1); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(MakeCellActive.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the workbook. | |
Worksheet worksheet1 = workbook.getWorksheets().get(0); | |
// Get the cells in the worksheet. | |
Cells cells = worksheet1.getCells(); | |
// Input data into B2 cell. | |
cells.get(1, 1).setValue("Hello World!"); | |
// Set the first sheet as an active sheet. | |
workbook.getWorksheets().setActiveSheetIndex(0); | |
// Set B2 cell as an active cell in the worksheet. | |
worksheet1.setActiveCell("B2"); | |
// Set the B column as the first visible column in the worksheet. | |
worksheet1.setFirstVisibleColumn(1); | |
// Set the 2nd row as the first visible row in the worksheet. | |
worksheet1.setFirstVisibleRow(1); | |
// Save the Excel file. | |
workbook.save(dataDir + "activecell.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Orientation.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Merging the first three columns in the first row to create a single cell | |
cells.merge(0, 0, 1, 3); | |
// Saved style | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Orientation.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Setting the rotation of the text (inside the cell) to 25 | |
Style style1 = cell.getStyle(); | |
style1.setRotationAngle(25); | |
cell.setStyle(style1); | |
// Saved style | |
cell.setStyle(style1); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SelectRangeofCellsinWorksheet.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the workbook. | |
Worksheet worksheet1 = workbook.getWorksheets().get(0); | |
// Get the cells in the worksheet. | |
Cells cells = worksheet1.getCells(); | |
// Input data into B2 cell. | |
cells.get(1, 1).setValue("Hello World!"); | |
// Set the first sheet as an active sheet. | |
workbook.getWorksheets().setActiveSheetIndex(0); | |
// Select range of cells(A1:E10) in the worksheet. | |
worksheet1.selectRange(0, 0, 10, 5, true); | |
// Save the Excel file. | |
workbook.save(dataDir + "activecells.xlsx"); |
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-Java | |
// Path to source file | |
String dataDir = Utils.getDataDir(SetBorder.class); | |
Style style = fc.getStyle(); | |
style.setBorder(BorderType.LEFT_BORDER, CellBorderType.DASHED, Color.fromArgb(0, 255, 255)); | |
style.setBorder(BorderType.TOP_BORDER, CellBorderType.DASHED, Color.fromArgb(0, 255, 255)); | |
style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.DASHED, Color.fromArgb(0, 255, 255)); | |
style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.DASHED, Color.fromArgb(255, 255, 0)); | |
fc.setStyle(style); | |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingFontName.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font color to blue | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setColor(Color.getBlue()); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingFontName.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font weight to bold | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSize(14); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingFontName.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font weight to bold | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setBold(true); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// Path to source file | |
String dataDir = Utils.getDataDir(SetBorder.class); | |
Style style = fc.getStyle(); | |
style.setPattern(BackgroundType.REVERSE_DIAGONAL_STRIPE); | |
style.setForegroundColor(Color.fromArgb(255, 255, 0)); | |
style.setBackgroundColor(Color.fromArgb(0, 255, 255)); | |
fc.setStyle(style); |
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-Java | |
// Setting subscript effect | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSubscript(true); | |
cell.setStyle(style); | |
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-Java | |
//Setting superscript effect | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setSuperscript(true); | |
cell.setStyle(style); | |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingDisplayFormat.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first (default) worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Adding a new Style to the styles collection of the Workbook object | |
Style style = workbook.createStyle(); | |
// Setting the Number property to 4 which corresponds to the pattern #,##0.00 | |
style.setNumber(4); | |
// Creating an object of StyleFlag | |
StyleFlag flag = new StyleFlag(); | |
// Setting NumberFormat property to true so that only this aspect takes effect from Style object | |
flag.setNumberFormat(true); | |
// Applying style to the first row of the worksheet | |
worksheet.getCells().getRows().get(0).applyStyle(style, flag); | |
// Re-initializing the Style object | |
style = workbook.createStyle(); | |
// Setting the Custom property to the pattern d-mmm-yy | |
style.setCustom("d-mmm-yy"); | |
// Applying style to the first column of the worksheet | |
worksheet.getCells().getColumns().get(0).applyStyle(style, flag); | |
// Saving spreadsheet on disc | |
workbook.save(dataDir + "output.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingFontName.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font name to "Times New Roman" | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setName("Times New Roman"); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// Path to source file | |
String dataDir = Utils.getDataDir(SettingFontStyle.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
FormatCondition fc; | |
Style style = fc.getStyle(); | |
Font font = style.getFont(); | |
font.setItalic(true); | |
font.setBold(true); | |
font.setStrikeout(true); | |
font.setUnderline(FontUnderlineType.DOUBLE); | |
font.setColor(Color.getBlack()); | |
fc.setStyle(style); | |
// Saving the Excel file | |
workbook.save(dataDir + "book1.out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingFontName.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding some value to the "A1" cell | |
Cell cell = cells.get("A1"); | |
cell.setValue("Hello Aspose!"); | |
// Setting the font to be underlined | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setUnderline(FontUnderlineType.SINGLE); | |
cell.setStyle(style); | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// Setting the strike out effect on the font | |
Style style = cell.getStyle(); | |
Font font = style.getFont(); | |
font.setStrikeout(true); | |
cell.setStyle(style); | |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Orientation.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Shrinking the text to fit according to the dimensions of the cell | |
Style style1 = cell.getStyle(); | |
style1.setShrinkToFit(true); | |
cell.setStyle(style1); | |
// Saved style | |
cell.setStyle(style1); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(TextAlignmentHorizontal.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
style.setHorizontalAlignment(TextAlignmentType.CENTER); | |
// Saved style | |
cell.setStyle(style); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(TextAlignmentVertical.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Setting the vertical alignment of the text in a cell | |
Style style1 = cell.getStyle(); | |
style1.setVerticalAlignment(TextAlignmentType.CENTER); | |
cell.setStyle(style1); | |
// Saved style | |
cell.setStyle(style1); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Orientation.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Accessing the added worksheet in the Excel file | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = worksheet.getCells(); | |
// Adding the current system date to "A1" cell | |
Cell cell = cells.get("A1"); | |
Style style = cell.getStyle(); | |
// Adding some value to the "A1" cell | |
cell.setValue("Visit Aspose!"); | |
// Enabling the text to be wrapped within the cell | |
Style style1 = cell.getStyle(); | |
style1.setTextWrapped(true); | |
cell.setStyle(style1); | |
// Saved style | |
cell.setStyle(style1); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CalculatingFormulas.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int sheetIndex = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
// Adding a value to "A1" cell | |
worksheet.getCells().get("A1").putValue(1); | |
// Adding a value to "A2" cell | |
worksheet.getCells().get("A2").putValue(2); | |
// Adding a value to "A3" cell | |
worksheet.getCells().get("A3").putValue(3); | |
// Adding a SUM formula to "A4" cell | |
worksheet.getCells().get("A4").setFormula("=SUM(A1:A3)"); | |
// Calculating the results of formulas | |
workbook.calculateFormula(); | |
// Get the calculated value of the cell | |
String value = worksheet.getCells().get("A4").getStringValue(); | |
// Saving the Excel file | |
workbook.save(dataDir + "test.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CalculatingFormulas.class) + "formulas/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int sheetIndex = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
// Adding a value to "A1" cell | |
worksheet.getCells().get("A1").putValue(1); | |
// Adding a value to "A2" cell | |
worksheet.getCells().get("A2").putValue(2); | |
// Adding a value to "A3" cell | |
worksheet.getCells().get("A3").putValue(3); | |
// Adding a SUM formula to "A4" cell | |
worksheet.getCells().get("A4").setFormula("=SUM(A1:A3)"); | |
// Calculating the results of formulas | |
workbook.calculateFormula(); | |
// Get the calculated value of the cell | |
String value = worksheet.getCells().get("A4").getStringValue(); | |
// Saving the Excel file | |
workbook.save(dataDir + "CalculatingFormulas_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CalculatingFormulasOnce.class); | |
// Load the template workbook | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Print the time before formula calculation | |
System.out.println(DateTime.getNow()); | |
// Set the CreateCalcChain as false | |
workbook.getSettings().setCreateCalcChain(false); | |
// Calculate the workbook formulas | |
workbook.calculateFormula(); | |
// Print the time after formula calculation | |
System.out.println(DateTime.getNow()); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CalculatingFormulasOnce.class) + "formulas/"; | |
// Load the template workbook | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Print the time before formula calculation | |
System.out.println(DateTime.getNow()); | |
// Set the CreateCalcChain as false | |
workbook.getSettings().setCreateCalcChain(false); | |
// Calculate the workbook formulas | |
workbook.calculateFormula(); | |
// Print the time after formula calculation | |
System.out.println(DateTime.getNow()); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DirectCalculationFormula.class); | |
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Put 20 in cell A1 | |
Cell cellA1 = worksheet.getCells().get("A1"); | |
cellA1.putValue(20); | |
// Put 30 in cell A2 | |
Cell cellA2 = worksheet.getCells().get("A2"); | |
cellA2.putValue(30); | |
// Calculate the Sum of A1 and A2 | |
Object results = worksheet.calculateFormula("=Sum(A1:A2)"); | |
// Print the output | |
System.out.println("Value of A1: " + cellA1.getStringValue()); | |
System.out.println("Value of A2: " + cellA2.getStringValue()); | |
System.out.println("Result of Sum(A1:A2): " + results.toString()); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(DirectCalculationFormula.class) + "formulas/"; | |
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Put 20 in cell A1 | |
Cell cellA1 = worksheet.getCells().get("A1"); | |
cellA1.putValue(20); | |
// Put 30 in cell A2 | |
Cell cellA2 = worksheet.getCells().get("A2"); | |
cellA2.putValue(30); | |
// Calculate the Sum of A1 and A2 | |
Object results = worksheet.calculateFormula("=Sum(A1:A2)"); | |
// Print the output | |
System.out.println("Value of A1: " + cellA1.getStringValue()); | |
System.out.println("Value of A2: " + cellA2.getStringValue()); | |
System.out.println("Result of Sum(A1:A2): " + results.toString()); |
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-Java | |
// Setting an add-in formula on the "H11" cell of the worksheet | |
worksheet.getCells().get("H11").setAddInFormula("HRVSTTRK.xla", "=pct_overcut(F3:G3)"); |
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-Java | |
// Setting an array formula on the cell "G2" | |
worksheet.getCells().get("G2").setArrayFormula("=LINEST(E2:E12,A2:D12,TRUE,TRUE)", 5, 3); |
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-Java | |
// Setting a complex formula on the 1st cell of the Cells collection of a worksheet | |
worksheet.getCells().get(0).setFormula("=H7*(1+IF(P7 =$L$3,$M$3, (IF(P7=$L$4,$M$4,0))))"); |
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-Java | |
// Setting an R1C1 formula on the "A1" cell | |
worksheet.getCells().get("A1").setR1C1Formula("=SUM(R[1]C[3]:R[3]C[4])"); |
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-Java | |
try { | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
System.out.println(CellsHelper.getVersion()); | |
} | |
catch (Exception ee) { | |
System.out.println(ee); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreatingWorkbook.class); | |
// Creating a file input stream to reference the license file | |
FileInputStream fstream = new FileInputStream("Aspose.Cells.lic"); | |
// Create a License object | |
License license = new License(); | |
// Applying the Aspose.Cells license | |
license.setLicense(fstream); | |
// Instantiating a Workbook object that represents a Microsoft Excel | |
// file. | |
Workbook wb = new Workbook(); | |
// Note when you create a new workbook, a default worksheet, "Sheet1", is by default added to the workbook. Accessing the | |
// first worksheet in the book ("Sheet1"). | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Access cell "A1" in the sheet. | |
Cell cell = sheet.getCells().get("A1"); | |
// Input the "Hello World!" text into the "A1" cell | |
cell.setValue("Hello World!"); | |
// Save the Microsoft Excel file. | |
wb.save(dataDir + "MyBook.xls", FileFormatType.EXCEL_97_TO_2003); | |
wb.save(dataDir + "MyBook.xlsx"); | |
wb.save(dataDir + "MyBook.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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreatingWorkbook.class) + "introduction/"; | |
// Creating a file input stream to reference the license file | |
FileInputStream fstream = new FileInputStream(dataDir + "Aspose.Cells.lic"); | |
// Create a License object | |
License license = new License(); | |
// Applying the Aspose.Cells license | |
license.setLicense(fstream); | |
// Instantiating a Workbook object that represents a Microsoft Excel file. | |
Workbook wb = new Workbook(); | |
// Note when you create a new workbook, a default worksheet, "Sheet1", is by default added to the workbook. Accessing the | |
// first worksheet in the book ("Sheet1"). | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Access cell "A1" in the sheet. | |
Cell cell = sheet.getCells().get("A1"); | |
// Input the "Hello World!" text into the "A1" cell | |
cell.setValue("Hello World!"); | |
// Save the Microsoft Excel file. | |
wb.save(dataDir + "CreatingWorkbook_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
wb.save(dataDir + "CreatingWorkbook_out.xlsx"); | |
wb.save(dataDir + "CreatingWorkbook_out.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-Java | |
String cellname = CellsHelper.cellIndexToName(0, 0); | |
System.out.println("Cell Name at [0, 0]: " + cellname); | |
cellname = CellsHelper.cellIndexToName(4, 0); | |
System.out.println("Cell Name at [4, 0]: " + cellname); | |
cellname = CellsHelper.cellIndexToName(0, 4); | |
System.out.println("Cell Name at [0, 4]: " + cellname); | |
cellname = CellsHelper.cellIndexToName(2, 2); | |
System.out.println("Cell Name at [2, 2]: " + cellname); |
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-Java | |
int[] cellIndices = CellsHelper.cellNameToIndex("C6"); | |
System.out.println("Row Index of Cell C6: " + cellIndices[0]); | |
System.out.println("Column Index of Cell C6: " + cellIndices[1]); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(OpeningExistingFile.class); | |
// Creating a file input stream to reference the license file | |
FileInputStream fstream = new FileInputStream("Aspose.Cells.lic"); | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.setLicense(fstream); | |
// Instantiate a Workbook object that represents an Excel file | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the reference of "A1" cell from the cells of a worksheet | |
Cell cell = workbook.getWorksheets().get(0).getCells().get("A1"); | |
// Set the "Hello World!" value into the "A1" cell | |
cell.setValue("Hello World!"); | |
// Write the Excel file | |
workbook.save(dataDir + "HelloWorld.xls", FileFormatType.EXCEL_97_TO_2003); | |
workbook.save(dataDir + "HelloWorld.xlsx"); | |
workbook.save(dataDir + "HelloWorld.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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningExistingFile.class) + "introduction/"; | |
// Creating a file input stream to reference the license file | |
FileInputStream fstream = new FileInputStream("Aspose.Cells.lic"); | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.setLicense(fstream); | |
// Instantiate a Workbook object that represents an Excel file | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the reference of "A1" cell from the cells of a worksheet | |
Cell cell = workbook.getWorksheets().get(0).getCells().get("A1"); | |
// Set the "Hello World!" value into the "A1" cell | |
cell.setValue("Hello World!"); | |
// Write the Excel file | |
workbook.save(dataDir + "OpeningExistingFile_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
workbook.save(dataDir + "OpeningExistingFile_out.xlsx"); | |
workbook.save(dataDir + "OpeningExistingFile_out.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-tasks/Aspose.Cells-for-Java | |
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xls"); | |
// Retrieve a list of all custom document properties of the Excel file | |
DocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties(); | |
// Accessing a custom document property by using the property name | |
DocumentProperty customProperty1 = customProperties.get("ContentTypeId"); | |
System.out.println(customProperty1.getName() + " " + customProperty1.getValue()); | |
// Accessing a custom document property by using the property index | |
DocumentProperty customProperty2 = customProperties.get(0); | |
System.out.println(customProperty2.getName() + " " + customProperty2.getValue()); |
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-tasks/Aspose.Cells-for-Java | |
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xls"); | |
// Retrieve a list of all custom document properties of the Excel file | |
DocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties(); | |
// Accessing a custom document property | |
DocumentProperty customProperty1 = customProperties.get(0); | |
// Storing the value of the document property as an object | |
Object objectValue = customProperty1.getValue(); | |
// Accessing a custom document property | |
DocumentProperty customProperty2 = customProperties.get(1); | |
// Checking the type of the document property and then storing the value of the | |
// document property according to that type | |
if (customProperty2.getType() == PropertyType.STRING) | |
{ | |
String value = customProperty2.getValue().toString(); | |
} |
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-tasks/Aspose.Cells-for-Java | |
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Retrieve a list of all custom document properties of the Excel file | |
CustomDocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties(); | |
// Adding a custom document property to the Excel file | |
DocumentProperty publisher = customProperties.add("Publisher", "Aspose"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AdvancedConversiontoPdf.class) + "loading_saving/"; | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
Cells cell = workbook.getWorksheets().get(0).getCells(); | |
cell.get("A12").setValue("Test PDF"); | |
PdfSaveOptions pdfOptions = new PdfSaveOptions(); | |
pdfOptions.setCompliance(PdfCompliance.PDF_A_1_B); | |
workbook.save(dataDir + "ACToPdf_out.pdf", pdfOptions); | |
// Print message | |
System.out.println("Advanced Conversion performed successfully."); |
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-tasks/Aspose.Cells-for-Java | |
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Retrieve a list of all custom document properties of the Excel file | |
CustomDocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties(); | |
// Add link to content. | |
customProperties.addLinkToContent("Owner", "MyRange"); | |
// Accessing the custom document property by using the property name | |
DocumentProperty customProperty1 = customProperties.get("Owner"); | |
// Check whether the property is lined to content | |
Boolean islinkedtocontent = customProperty1.isLinkedToContent(); | |
// Get the source for the property | |
String source = customProperty1.getSource(); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertingsingleWorksheetToXPS.class) + "loading_saving/"; | |
//Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
//Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
//Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
//Set the format | |
options.setSaveFormat(SaveFormat.XPS); | |
//Render the sheet with respect to specified printing options | |
SheetRender render = new SheetRender(sheet, options); | |
render.toImage(0, dataDir + "CSingleWorksheetToXPS_out.xps"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertingToHTMLFiles.class) + "loading_saving/"; | |
// Specify the file path | |
String filePath = dataDir + "Book1.xlsx"; | |
// Specify the HTML saving options | |
HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.M_HTML); | |
// Instantiate a workbook and open the template XLSX file | |
Workbook wb = new Workbook(filePath); | |
// Save the HTML file | |
wb.save(dataDir + "CToHTMLFiles_out.html", sv); | |
// Print message | |
System.out.println("Excel to HTML conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertingToMHTMLFiles.class) + "loading_saving/"; | |
// Specify the file path | |
String filePath = dataDir + "Book1.xlsx"; | |
// Specify the HTML saving options | |
HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.M_HTML); | |
// Instantiate a workbook and open the template XLSX file | |
Workbook wb = new Workbook(filePath); | |
// Save the MHT file | |
wb.save(dataDir + "CToMHTMLFiles_out.mht", sv); | |
// Print message | |
System.out.println("Excel to MHTML conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertingToXPS.class) + "loading_saving/"; | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Apply different Image and Print options | |
com.aspose.cells.ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set the Format | |
options.setSaveFormat(SaveFormat.XPS); | |
// Render the sheet with respect to specified printing options | |
com.aspose.cells.SheetRender sr = new SheetRender(sheet, options); | |
sr.toImage(0, dataDir + "ConvertingToXPS_out.xps"); | |
// Save the complete Workbook in XPS format | |
workbook.save(dataDir + "ConvertingToXPS_out.xps", SaveFormat.XPS); | |
// Print message | |
System.out.println("Excel to XPS conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertingWorksheetToSVG.class) + "loading_saving/"; | |
String path = dataDir + "Book1.xlsx"; | |
// Create a workbook object from the template file | |
Workbook workbook = new Workbook(path); | |
// Convert each worksheet into svg format in a single page. | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
imgOptions.setSaveFormat(SaveFormat.SVG); | |
imgOptions.setOnePagePerSheet(true); | |
// Convert each worksheet into svg format | |
int sheetCount = workbook.getWorksheets().getCount(); | |
for (int i = 0; i < sheetCount; i++) { | |
Worksheet sheet = workbook.getWorksheets().get(i); | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int k = 0; k < sr.getPageCount(); k++) { | |
// Output the worksheet into Svg image format | |
sr.toImage(k, path + sheet.getName() + k + "_out.svg"); | |
} | |
} | |
// Print message | |
System.out.println("Excel to SVG conversion completed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(EncryptingFiles.class) + "loading_saving/"; | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Password protect the file. | |
workbook.getSettings().setPassword("1234"); | |
// Specify XOR encrption type. | |
workbook.setEncryptionOptions(EncryptionType.XOR, 40); | |
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic | |
// Provider). | |
workbook.setEncryptionOptions(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128); | |
// Save the excel file. | |
workbook.save(dataDir + "EncryptingFiles_out.xls"); | |
// Print message | |
System.out.println("Encryption applied successfully on output file."); |
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-Java | |
// The path to the documents directory. | |
static String sourceDir = Utils.Get_SourceDirectory(); | |
static String outputDir = Utils.Get_OutputDirectory(); | |
public static void main(String[] args) throws Exception { | |
//Encrypt an ODS file | |
//Encrypted ODS file can only be opened in OpenOffice as Excel does not support encrypted ODS files | |
//Initialize loading options | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.ODS); | |
// Instantiate a Workbook object. | |
// Open an ODS file. | |
Workbook workbook = new Workbook(sourceDir + "sampleODSFile.ods", loadOptions); | |
//Encryption options are not effective for ODS files | |
// Password protect the file. | |
workbook.getSettings().setPassword("1234"); | |
// Save the excel file. | |
workbook.save(outputDir + "outputEncryptedODSFile.ods"); | |
//Decrypt ODS file | |
//Decrypted ODS file can be opened both in Excel and OpenOffice | |
// Set original password | |
loadOptions.setPassword("1234"); | |
// Load the encrypted ODS file with the appropriate load options | |
Workbook encrypted = new Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions); | |
// Unprotect the workbook | |
encrypted.unprotect("1234"); | |
// Set the password to null | |
encrypted.getSettings().setPassword(null); | |
// Save the decrypted ODS file | |
encrypted.save(outputDir + "outputDecryptedODSFile.ods"); | |
// Print message | |
System.out.println("Encryption and Decryption applied successfully on ODS file."); | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(Excel2PDFConversion.class) + "loading_saving/"; | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Save the document in PDF format | |
workbook.save(dataDir + "E2PDFC-out.pdf", SaveFormat.PDF); | |
// Print message | |
System.out.println("Excel to PDF conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExportWholeWorkbookToXPS.class) + "loading_saving/"; | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set the format | |
options.setSaveFormat(SaveFormat.XPS); | |
// Render the workbook with respect to specified printing options | |
WorkbookRender render = new WorkbookRender(workbook, options); | |
render.toImage(dataDir + "ExportWholeWorkbookToXPS_out.xps"); |
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
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(GetWarningLoadingAnExcel.class) + "loading_saving/"; | |
//Create load options and set the WarningCallback property | |
//to catch warnings while loading workbook | |
LoadOptions options = new LoadOptions(); | |
options.setWarningCallback(new WarningCallback()); | |
//Load the source excel file | |
Workbook book = new Workbook(dataDir + "sampleDuplicateDefinedName.xlsx", options); | |
//Save the workbook | |
book.save(dataDir + "outputDuplicateDefinedName.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningCSVFiles.class) + "loading_saving/"; | |
// Opening CSV Files | |
// Creating and CSV LoadOptions object | |
LoadOptions loadOptions4 = new LoadOptions(FileFormatType.CSV); | |
// Creating an Workbook object with CSV file path and the loadOptions | |
// object | |
Workbook workbook6 = new Workbook(dataDir + "Book_CSV.csv", loadOptions4); | |
// Print message | |
System.out.println("CSV format workbook has been opened successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningEncryptedExcelFiles.class) + "loading_saving/"; | |
// Opening Encrypted Excel Files | |
// Creating and EXCEL_97_TO_2003 LoadOptions object | |
LoadOptions loadOptions6 = new LoadOptions(FileFormatType.EXCEL_97_TO_2003); | |
// Setting the password for the encrypted Excel file | |
loadOptions6.setPassword("1234"); | |
// Creating an Workbook object with file path and the loadOptions object | |
Workbook workbook8 = new Workbook(dataDir + "encryptedBook.xls", loadOptions6); | |
// Print message | |
System.out.println("Encrypted workbook has been opened successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningFilesThroughPath.class) + "files/"; | |
// Opening from path. | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook1 = new Workbook(dataDir + "Book1.xlsx"); | |
// Print message | |
System.out.println("Workbook opened using path successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningFilesThroughStream.class) + "loading_saving/"; | |
// Opening workbook from stream | |
// Create a Stream object | |
FileInputStream fstream = new FileInputStream(dataDir + "Book2.xls"); | |
// Creating an Workbook object with the stream object | |
Workbook workbook2 = new Workbook(fstream); | |
fstream.close(); | |
// Print message | |
System.out.println("Workbook opened using stream successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningMicrosoftExcel2007XlsxFiles.class) + "loading_saving/"; | |
String filePath = dataDir + "Book1.html"; | |
// Opening Microsoft Excel 2007 XLSX Files. Createing and XLSX LoadOptions object | |
LoadOptions loadOptions2 = new LoadOptions(FileFormatType.XLSX); | |
// Creating an Workbook object with 2007 xlsx file path and the loadOptions object | |
Workbook workbook4 = new Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2); | |
// Print message | |
System.out.println("Excel 2007 Workbook opened successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningMicrosoftExcel972003Files.class) + "loading_saving/"; | |
// Opening Microsoft Excel 97 Files | |
// Createing and EXCEL_97_TO_2003 LoadOptions object | |
LoadOptions loadOptions1 = new LoadOptions(FileFormatType.EXCEL_97_TO_2003); | |
// Creating an Workbook object with excel 97 file path and the | |
// loadOptions object | |
Workbook workbook3 = new Workbook(dataDir + "Book_Excel97_2003.xls", loadOptions1); | |
// Print message | |
System.out.println("Excel 97 Workbook opened successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningSpreadsheetMLFiles.class) + "loading_saving/"; | |
// Opening SpreadsheetML Files | |
// Creating and EXCEL_2003_XML LoadOptions object | |
LoadOptions loadOptions3 = new LoadOptions(FileFormatType.EXCEL_2003_XML); | |
// Creating an Workbook object with SpreadsheetML file path and the | |
// loadOptions object | |
Workbook workbook5 = new Workbook(dataDir + "Book3.xml", loadOptions3); | |
// Print message | |
System.out.println("SpreadSheetML format workbook has been opened successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(OpeningTabDelimitedFiles.class) + "loading_saving/"; | |
String filePath = dataDir + "Book1.html"; | |
// Creating and TAB_DELIMITED LoadOptions object | |
LoadOptions loadOptions5 = new LoadOptions(FileFormatType.TAB_DELIMITED); | |
// Creating an Workbook object with Tab Delimited text file path and the | |
// loadOptions object | |
Workbook workbook7 = new Workbook(dataDir + "Book1TabDelimited.txt", loadOptions5); | |
// Print message | |
System.out.println("Tab Delimited workbook has been opened successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExportWholeWorkbookToXPS.class) + "loading_saving/"; | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Save in XPS format | |
workbook.save("QEToXPSConversion_out.xps", SaveFormat.XPS); |
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-tasks/Aspose.Cells-for-Java | |
// Instantiate a Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Retrieve a list of all custom document properties of the Excel file | |
DocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties(); | |
// Removing a custom document property | |
customProperties.remove("Publisher"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SaveInPdfFormat.class) + "loading_saving/"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in PDF format | |
workbook.save(dataDir + "SIPdfFormat_out.pdf", FileFormatType.PDF); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SaveWorkbookToTextCSVFormat.class) + "loading_saving/"; | |
// Load your source workbook | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// 0-byte array | |
byte[] workbookData = new byte[0]; | |
// Text save options. You can use any type of separator | |
TxtSaveOptions opts = new TxtSaveOptions(); | |
opts.setSeparator('\t'); | |
// Copy each worksheet data in text format inside workbook data array | |
for (int idx = 0; idx < workbook.getWorksheets().getCount(); idx++) { | |
// Save the active worksheet into text format | |
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | |
workbook.getWorksheets().setActiveSheetIndex(idx); | |
workbook.save(bout, opts); | |
// Save the worksheet data into sheet data array | |
byte[] sheetData = bout.toByteArray(); | |
// Combine this worksheet data into workbook data array | |
byte[] combinedArray = new byte[workbookData.length + sheetData.length]; | |
System.arraycopy(workbookData, 0, combinedArray, 0, workbookData.length); | |
System.arraycopy(sheetData, 0, combinedArray, workbookData.length, sheetData.length); | |
workbookData = combinedArray; | |
} | |
// Save entire workbook data into file | |
FileOutputStream fout = new FileOutputStream(dataDir + "SWTTextCSVFormat-out.txt"); | |
fout.write(workbookData); | |
fout.close(); | |
// Print message | |
System.out.println("Excel to Text File Conversion performed successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SaveXLSFile.class) + "loading_saving/"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in xls format | |
workbook.save(dataDir + "SXLSFile_out.xls", FileFormatType.EXCEL_97_TO_2003); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SaveXLSXFile.class) + "loading_saving/"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(); | |
// Save in xlsx format | |
workbook.save(dataDir + "SXLSXFile_out.xlsx", FileFormatType.XLSX); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SavingFiletoSomeLocation.class) + "loading_saving/"; | |
String filePath = dataDir + "Book1.xls"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(filePath); | |
// Save in Excel 97 – 2003 format | |
workbook.save(dataDir + "SFTSomeLocation_out.xls"); | |
// OR | |
// workbook.save(dataDir + ".output..xls", new | |
// XlsSaveOptions(SaveFormat.Excel97To2003)); | |
// Save in Excel2007 xlsx format | |
workbook.save(dataDir + "SFTSomeLocation_out.xlsx", FileFormatType.XLSX); | |
// Save in Excel2007 xlsb format | |
workbook.save(dataDir + "SFTSomeLocation_out.xlsb", FileFormatType.XLSB); | |
// Save in ODS format | |
workbook.save(dataDir + "SFTSomeLocation_out.ods", FileFormatType.ODS); | |
// Save in Pdf format | |
workbook.save(dataDir + "SFTSomeLocation_out.pdf", FileFormatType.PDF); | |
// Save in Html format | |
workbook.save(dataDir + "SFTSomeLocation_out.html", FileFormatType.HTML); | |
// Save in SpreadsheetML format | |
workbook.save(dataDir + "SFTSomeLocation_out.xml", FileFormatType.EXCEL_2003_XML); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SavingFiletoStream.class) + "loading_saving/"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
FileOutputStream stream = new FileOutputStream(dataDir + "SFToStream_out.xlsx"); | |
workbook.save(stream, new XpsSaveOptions(FileFormatType.XLSX)); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); | |
stream.close(); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SavingTextFilewithCustomSeparator.class) + "loading_saving/"; | |
// Creating an Workbook object with an Excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
TxtSaveOptions toptions = new TxtSaveOptions(); | |
// Specify the separator | |
toptions.setSeparator(';'); | |
workbook.save(dataDir + "STFWCSeparator_out.csv"); | |
// Print Message | |
System.out.println("Worksheets are saved successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingImagePrefrencesforHTML.class) + "loading_saving/"; | |
// Instantiate a Workbook object by excel file path | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
System.out.println("Set PDF Creation Time successfully."); |
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
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(TrimBlankRowsAndColsWhileExportingSpreadsheetsToCSVFormat.class) + "loading_saving\\"; | |
//Load source worbook | |
Workbook wb = new Workbook(dataDir + "sampleTrimBlankColumns.xlsx"); | |
//Save in csv format | |
wb.save(dataDir + "outputWithoutTrimBlankColumns.csv", SaveFormat.CSV); | |
//Now save again with TrimLeadingBlankRowAndColumn as true | |
TxtSaveOptions opts = new TxtSaveOptions(); | |
opts.setTrimLeadingBlankRowAndColumn(true); | |
//Save in csv format | |
wb.save(dataDir + "outputTrimBlankColumns.csv", opts); |
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
//Implement IWarningCallback interface to catch warnings while loading workbook | |
public class WarningCallback implements IWarningCallback | |
{ | |
public void warning(WarningInfo warningInfo) | |
{ | |
if(warningInfo.getWarningType() == WarningType.DUPLICATE_DEFINED_NAME) | |
{ | |
System.out.println("Duplicate Defined Name Warning: " + warningInfo.getDescription()); | |
} | |
} | |
} |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(WorksheetToImage.class) + "loading_saving/"; | |
// Instantiate a new workbook with path to an Excel file | |
Workbook book = new Workbook(dataDir + "MyTestBook1.xlsx"); | |
// Create an object for ImageOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the image type | |
imgOptions.setImageFormat(ImageFormat.getPng()); | |
// Get the first worksheet. | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Create a SheetRender object for the target sheet | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int j = 0; j < sr.getPageCount(); j++) { | |
// Generate an image for the worksheet | |
sr.toImage(j, dataDir + "WToImage-out" + j + ".png"); | |
} | |
// Print message | |
System.out.println("Images generated successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangeSourceData.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Populating new data to the worksheet cells | |
Cells cells = worksheet.getCells(); | |
Cell cell = cells.get("A9"); | |
cell.setValue("Golf"); | |
cell = cells.get("B9"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("C9"); | |
cell.setValue(7000); | |
// Changing named range "DataSource" | |
Range range = cells.createRange(0, 0, 8, 2); | |
range.setName("DataSource"); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ChangeSourceData.class) + "PivotTables/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Populating new data to the worksheet cells | |
Cells cells = worksheet.getCells(); | |
Cell cell = cells.get("A9"); | |
cell.setValue("Golf"); | |
cell = cells.get("B9"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("C9"); | |
cell.setValue(7000); | |
// Changing named range "DataSource" | |
Range range = cells.createRange(0, 0, 8, 2); | |
range.setName("DataSource"); | |
// Saving the modified Excel file in default format | |
workbook.save(dataDir + "ChangeSourceData_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ClearPivotFields.class); | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the pivot tables in the sheet | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
// Get the first PivotTable | |
PivotTable pivotTable = pivotTables.get(0); | |
// Clear all the data fields | |
pivotTable.getDataFields().clear(); | |
// Add new data field | |
pivotTable.addFieldToArea(PivotFieldType.DATA, "Betrag Netto FW"); | |
// Set the refresh data flag on | |
pivotTable.setRefreshDataFlag(false); | |
// Refresh and calculate the pivot table data | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Save the Excel file | |
workbook.save(dataDir + "out1.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ClearPivotFields.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the pivot tables in the sheet | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
// Get the first PivotTable | |
PivotTable pivotTable = pivotTables.get(0); | |
// Clear all the data fields | |
pivotTable.getDataFields().clear(); | |
// Add new data field | |
pivotTable.addFieldToArea(PivotFieldType.DATA, "Betrag Netto FW"); | |
// Set the refresh data flag on | |
pivotTable.setRefreshDataFlag(false); | |
// Refresh and calculate the pivot table data | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Save the Excel file | |
workbook.save(dataDir + "ClearPivotFields_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConsolidationFunctions.class); | |
// Create workbook from source excel file | |
Workbook workbook = new Workbook(dataDir + "Book.xlsx"); | |
// Access the first worksheet of the workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the first pivot table of the worksheet | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Apply Average consolidation function to first data field | |
pivotTable.getDataFields().get(0).setFunction(ConsolidationFunction.AVERAGE); | |
// Apply DistinctCount consolidation function to second data field | |
pivotTable.getDataFields().get(1).setFunction(ConsolidationFunction.DISTINCT_COUNT); | |
// Calculate the data to make changes affect | |
pivotTable.calculateData(); | |
// Save the workbook | |
workbook.save(dataDir + "output.xlsx"); | |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConsolidationFunctions.class) + "PivotTables/"; | |
// Create workbook from source excel file | |
Workbook workbook = new Workbook(dataDir + "sample1.xlsx"); | |
// Access the first worksheet of the workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the first pivot table of the worksheet | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Apply Average consolidation function to first data field | |
pivotTable.getDataFields().get(0).setFunction(ConsolidationFunction.AVERAGE); | |
// Apply DistinctCount consolidation function to second data field | |
pivotTable.getDataFields().get(1).setFunction(ConsolidationFunction.DISTINCT_COUNT); | |
// Calculate the data to make changes affect | |
pivotTable.calculateData(); | |
// Save the workbook | |
workbook.save(dataDir + "ConsolidationFunctions_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreatePivotTable.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the newly added worksheet | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet sheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = sheet.getCells(); | |
// Setting the value to the cells | |
Cell cell = cells.get("A1"); | |
cell.setValue("Sport"); | |
cell = cells.get("B1"); | |
cell.setValue("Quarter"); | |
cell = cells.get("C1"); | |
cell.setValue("Sales"); | |
cell = cells.get("A2"); | |
cell.setValue("Golf"); | |
cell = cells.get("A3"); | |
cell.setValue("Golf"); | |
cell = cells.get("A4"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A5"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A6"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A7"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A8"); | |
cell.setValue("Golf"); | |
cell = cells.get("B2"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("B3"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("B4"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("B5"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("B6"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("B7"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("B8"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("C2"); | |
cell.setValue(1500); | |
cell = cells.get("C3"); | |
cell.setValue(2000); | |
cell = cells.get("C4"); | |
cell.setValue(600); | |
cell = cells.get("C5"); | |
cell.setValue(1500); | |
cell = cells.get("C6"); | |
cell.setValue(4070); | |
cell = cells.get("C7"); | |
cell.setValue(5000); | |
cell = cells.get("C8"); | |
cell.setValue(6430); | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
// Adding a PivotTable to the worksheet | |
int index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
// Accessing the instance of the newly added PivotTable | |
PivotTable pivotTable = pivotTables.get(index); | |
// Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
// Dragging the first field to the row area. | |
pivotTable.addFieldToArea(PivotFieldType.ROW, 0); | |
// Dragging the second field to the column area. | |
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1); | |
// Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
// Saving the Excel file | |
workbook.save(dataDir + "book1.xls"); |
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-Java | |
// The path to the resource directory | |
String dataDir = Utils.getSharedDataDir(CreatePivotTable.class) + "PivotTables/"; | |
//Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
//Obtaining the reference of the newly added worksheet | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet sheet = workbook.getWorksheets().get(sheetIndex); | |
Cells cells = sheet.getCells(); | |
//Setting the value to the cells | |
Cell cell = cells.get("A1"); | |
cell.setValue("Sport"); | |
cell = cells.get("B1"); | |
cell.setValue("Quarter"); | |
cell = cells.get("C1"); | |
cell.setValue("Sales"); | |
cell = cells.get("A2"); | |
cell.setValue("Golf"); | |
cell = cells.get("A3"); | |
cell.setValue("Golf"); | |
cell = cells.get("A4"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A5"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A6"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A7"); | |
cell.setValue("Tennis"); | |
cell = cells.get("A8"); | |
cell.setValue("Golf"); | |
cell = cells.get("B2"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("B3"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("B4"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("B5"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("B6"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("B7"); | |
cell.setValue("Qtr4"); | |
cell = cells.get("B8"); | |
cell.setValue("Qtr3"); | |
cell = cells.get("C2"); | |
cell.setValue(1500); | |
cell = cells.get("C3"); | |
cell.setValue(2000); | |
cell = cells.get("C4"); | |
cell.setValue(600); | |
cell = cells.get("C5"); | |
cell.setValue(1500); | |
cell = cells.get("C6"); | |
cell.setValue(4070); | |
cell = cells.get("C7"); | |
cell.setValue(5000); | |
cell = cells.get("C8"); | |
cell.setValue(6430); | |
PivotTableCollection pivotTables = sheet.getPivotTables(); | |
//Adding a PivotTable to the worksheet | |
int index = pivotTables.add("=A1:C8", "E3", "PivotTable2"); | |
//Accessing the instance of the newly added PivotTable | |
PivotTable pivotTable = pivotTables.get(index); | |
//Unshowing grand totals for rows. | |
pivotTable.setRowGrand(false); | |
//Dragging the first field to the row area. | |
pivotTable.addFieldToArea(PivotFieldType.ROW, 0); | |
//Dragging the second field to the column area. | |
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1); | |
//Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
//Saving the Excel file | |
workbook.save(dataDir + "CreatePivotTable_out.xls"); |
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-Java | |
public class CustomizeGlobalizationSettingsforPivotTable { | |
class CustomPivotTableGlobalizationSettings extends GlobalizationSettings | |
{ | |
//Gets the name of "Total" label in the PivotTable. | |
//You need to override this method when the PivotTable contains two or more PivotFields in the data area. | |
public String getPivotTotalName() | |
{ | |
System.out.println("---------GetPivotTotalName-------------"); | |
return "AsposeGetPivotTotalName"; | |
} | |
//Gets the name of "Grand Total" label in the PivotTable. | |
public String getPivotGrandTotalName() | |
{ | |
System.out.println("---------GetPivotGrandTotalName-------------"); | |
return "AsposeGetPivotGrandTotalName"; | |
} | |
//Gets the name of "(Multiple Items)" label in the PivotTable. | |
public String getMultipleItemsName() | |
{ | |
System.out.println("---------GetMultipleItemsName-------------"); | |
return "AsposeGetMultipleItemsName"; | |
} | |
//Gets the name of "(All)" label in the PivotTable. | |
public String getAllName() | |
{ | |
System.out.println("---------GetAllName-------------"); | |
return "AsposeGetAllName"; | |
} | |
//Gets the name of "Column Labels" label in the PivotTable. | |
public String getColumnLablesName() | |
{ | |
System.out.println("---------GetColumnLablesName-------------"); | |
return "AsposeGetColumnLablesName"; | |
} | |
//Gets the name of "Row Labels" label in the PivotTable. | |
public String getRowLablesName() | |
{ | |
System.out.println("---------GetRowLablesName-------------"); | |
return "AsposeGetRowLablesName"; | |
} | |
//Gets the name of "(blank)" label in the PivotTable. | |
public String getEmptyDataName() | |
{ | |
System.out.println("---------GetEmptyDataName-------------"); | |
return "(blank)AsposeGetEmptyDataName"; | |
} | |
//Gets the name of PivotFieldSubtotalType type in the PivotTable. | |
public String getSubTotalName(int subTotalType) | |
{ | |
System.out.println("---------GetSubTotalName-------------"); | |
switch (subTotalType) | |
{ | |
case PivotFieldSubtotalType.SUM: | |
return "AsposeSum";//polish | |
case PivotFieldSubtotalType.COUNT: | |
return "AsposeCount"; | |
case PivotFieldSubtotalType.AVERAGE: | |
return "AsposeAverage"; | |
case PivotFieldSubtotalType.MAX: | |
return "AsposeMax"; | |
case PivotFieldSubtotalType.MIN: | |
return "AsposeMin"; | |
case PivotFieldSubtotalType.PRODUCT: | |
return "AsposeProduct"; | |
case PivotFieldSubtotalType.COUNT_NUMS: | |
return "AsposeCount"; | |
case PivotFieldSubtotalType.STDEV: | |
return "AsposeStdDev"; | |
case PivotFieldSubtotalType.STDEVP: | |
return "AsposeStdDevp"; | |
case PivotFieldSubtotalType.VAR: | |
return "AsposeVar"; | |
case PivotFieldSubtotalType.VARP: | |
return "AsposeVarp"; | |
} | |
return "AsposeSubTotalName"; | |
} | |
}//End CustomPivotTableGlobalizationSettings | |
public void RunCustomizeGlobalizationSettingsforPivotTable() throws Exception | |
{ | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CustomizeGlobalizationSettingsforPivotTable.class) + "PivotTables/"; | |
//Load your excel file | |
Workbook wb = new Workbook(dataDir + "samplePivotTableGlobalizationSettings.xlsx"); | |
//Setting Custom Pivot Table Globalization Settings | |
wb.getSettings().setGlobalizationSettings(new CustomPivotTableGlobalizationSettings()); | |
//Hide first worksheet that contains the data of the pivot table | |
wb.getWorksheets().get(0).setVisible(false); | |
//Access second worksheet | |
Worksheet ws = wb.getWorksheets().get(1); | |
//Access the pivot table, refresh and calculate its data | |
PivotTable pt = ws.getPivotTables().get(0); | |
pt.setRefreshDataFlag(true); | |
pt.refreshData(); | |
pt.calculateData(); | |
pt.setRefreshDataFlag(false); | |
//Pdf save options - save entire worksheet on a single pdf page | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setOnePagePerSheet(true); | |
//Save the output pdf | |
wb.save(dataDir + "outputPivotTableGlobalizationSettings.pdf", options); | |
} | |
public static void main(String[] args) throws Exception { | |
CustomizeGlobalizationSettingsforPivotTable pg = new CustomizeGlobalizationSettingsforPivotTable(); | |
pg.RunCustomizeGlobalizationSettingsforPivotTable(); | |
} | |
} |
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-Java | |
// Open the template file containing the pivot table | |
Workbook wb = new Workbook("pivot_table_test.xlsx"); | |
// Access the pivot table in the first sheet | |
PivotTable pt = wb.getWorksheets().get(0).getPivotTables().get(0); | |
// Disable ribbon for this pivot table | |
pt.setEnableWizard(false); | |
// Save output file | |
wb.save("out_java.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ModifyPivotTableQuickStyle.class); | |
// Open the template file containing the pivot table. | |
Workbook wb = new Workbook(dataDir + "sample1.xlsx"); | |
// Add Pivot Table style | |
Style style1 = wb.createStyle(); | |
com.aspose.cells.Font font1 = style1.getFont(); | |
font1.setColor(Color.getRed()); | |
Style style2 = wb.createStyle(); | |
com.aspose.cells.Font font2 = style2.getFont(); | |
font2.setColor(Color.getBlue()); | |
int i = wb.getWorksheets().getTableStyles().addPivotTableStyle("tt"); | |
// Get and Set the table style for different categories | |
TableStyle ts = wb.getWorksheets().getTableStyles().get(i); | |
int index = ts.getTableStyleElements().add(TableStyleElementType.FIRST_COLUMN); | |
TableStyleElement e = ts.getTableStyleElements().get(index); | |
e.setElementStyle(style1); | |
index = ts.getTableStyleElements().add(TableStyleElementType.GRAND_TOTAL_ROW); | |
e = ts.getTableStyleElements().get(index); | |
e.setElementStyle(style2); | |
// Set Pivot Table style name | |
PivotTable pt = wb.getWorksheets().get(0).getPivotTables().get(0); | |
pt.setPivotTableStyleName("tt"); | |
// Save the file. | |
wb.save(dataDir + "OutputFile.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ModifyPivotTableQuickStyle.class) + "PivotTables/"; | |
// Open the template file containing the pivot table. | |
Workbook wb = new Workbook(dataDir + "sample1.xlsx"); | |
// Add Pivot Table style | |
Style style1 = wb.createStyle(); | |
com.aspose.cells.Font font1 = style1.getFont(); | |
font1.setColor(Color.getRed()); | |
Style style2 = wb.createStyle(); | |
com.aspose.cells.Font font2 = style2.getFont(); | |
font2.setColor(Color.getBlue()); | |
int i = wb.getWorksheets().getTableStyles().addPivotTableStyle("tt"); | |
// Get and Set the table style for different categories | |
TableStyle ts = wb.getWorksheets().getTableStyles().get(i); | |
int index = ts.getTableStyleElements().add(TableStyleElementType.FIRST_COLUMN); | |
TableStyleElement e = ts.getTableStyleElements().get(index); | |
e.setElementStyle(style1); | |
index = ts.getTableStyleElements().add(TableStyleElementType.GRAND_TOTAL_ROW); | |
e = ts.getTableStyleElements().get(index); | |
e.setElementStyle(style2); | |
// Set Pivot Table style name | |
PivotTable pt = wb.getWorksheets().get(0).getPivotTables().get(0); | |
pt.setPivotTableStyleName("tt"); | |
// Save the file. | |
wb.save(dataDir + "ModifyPivotTableQuickStyle_out.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetAutoFormatandPivotTableStyleTypes.class); | |
PivotTable pivotTable = new PivotTable(); | |
// Setting the PivotTable report is automatically formatted for Excel 2003 formats | |
pivotTable.setAutoFormat(true); | |
// Setting the PivotTable atuoformat type. | |
pivotTable.setAutoFormatType(PivotTableAutoFormatType.CLASSIC); | |
// Setting the PivotTable's Styles for Excel 2007/2010 formats e.g XLSX. | |
pivotTable.setPivotTableStyleType(PivotTableStyleType.PIVOT_TABLE_STYLE_LIGHT_1); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetAutoFormatandPivotTableStyleTypes.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
int pivotindex = 0; | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(pivotindex); | |
// Accessing the PivotTable | |
PivotTable pivotTable = worksheet.getPivotTables().get(pivotindex); | |
//Setting the PivotTable report is automatically formatted for Excel 2003 formats | |
pivotTable.setAutoFormat(true); | |
//Setting the PivotTable atuoformat type. | |
pivotTable.setAutoFormatType(PivotTableAutoFormatType.CLASSIC); | |
//Setting the PivotTable's Styles for Excel 2007/2010 formats e.g XLSX. | |
pivotTable.setPivotTableStyleType(PivotTableStyleType.PIVOT_TABLE_STYLE_LIGHT_1); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetRowColumnPageFieldsFormat.class); | |
PivotTable pivotTable = new PivotTable(); | |
// Accessing the row fields. | |
PivotFieldCollection pivotFields = pivotTable.getRowFields(); | |
// Accessing the first row field in the row fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting Subtotals. | |
pivotField.setSubtotals(PivotFieldSubtotalType.SUM, true); | |
pivotField.setSubtotals(PivotFieldSubtotalType.COUNT, true); | |
// Setting autosort options. Setting the field auto sort. | |
pivotField.setAutoSort(true); | |
// Setting the field auto sort ascend. | |
pivotField.setAscendSort(true); | |
// Setting the field auto sort using the field itself. | |
pivotField.setAutoSortField(-1); | |
// Setting autoShow options. Setting the field auto show. | |
pivotField.setAutoShow(true); | |
// Setting the field auto show ascend. | |
pivotField.setAscendShow(false); | |
// Setting the auto show using field(data field). | |
pivotField.setAutoShowField(0); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetRowColumnPageFieldsFormat.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Accessing the row fields. | |
PivotFieldCollection pivotFields = pivotTable.getRowFields(); | |
// Accessing the first row field in the row fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting Subtotals. | |
pivotField.setSubtotals(PivotFieldSubtotalType.SUM, true); | |
pivotField.setSubtotals(PivotFieldSubtotalType.COUNT, true); | |
// Setting autosort options. Setting the field auto sort. | |
pivotField.setAutoSort(true); | |
// Setting the field auto sort ascend. | |
pivotField.setAscendSort(true); | |
// Setting the field auto sort using the field itself. | |
pivotField.setAutoSortField(-1); | |
// Setting autoShow options. Setting the field auto show. | |
pivotField.setAutoShow(true); | |
// Setting the field auto show ascend. | |
pivotField.setAscendShow(false); | |
// Setting the auto show using field(data field). | |
pivotField.setAutoShowField(0); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingDataFieldFormat.class); | |
PivotTable pivotTable = new PivotTable(); | |
// Accessing the data fields. | |
PivotFieldCollection pivotFields = pivotTable.getDataFields(); | |
// Accessing the first data field in the data fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting data display format | |
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.PERCENTAGE_OF); | |
// Setting the base field. | |
pivotField.setBaseField(1); | |
// Setting the base item. | |
pivotField.setBaseItem(PivotItemPosition.NEXT); | |
// Setting number format | |
pivotField.setNumber(10); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingDataFieldFormat.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Accessing the data fields. | |
PivotFieldCollection pivotFields = pivotTable.getDataFields(); | |
// Accessing the first data field in the data fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting data display format | |
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.PERCENTAGE_OF); | |
// Setting the base field. | |
pivotField.setBaseFieldIndex(1); | |
// Setting the base item. | |
pivotField.setBaseItemPosition(PivotItemPosition.NEXT); | |
// Setting number format | |
pivotField.setNumber(10); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingFormatOptions.class); | |
PivotTable pivotTable = new PivotTable(); | |
// Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
// Show grand totals for rows. | |
pivotTable.setRowGrand(true); | |
// Show grand totals for columns. | |
pivotTable.setColumnGrand(true); | |
// Display a custom string in cells that contain null values. | |
pivotTable.setDisplayNullString(true); | |
pivotTable.setNullString("null"); | |
// Setting the layout | |
pivotTable.setPageFieldOrder(PrintOrderType.DOWN_THEN_OVER); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingFormatOptions.class) + "PivotTables/"; | |
// Load a template file | |
Workbook workbook = new Workbook(dataDir + "PivotTable.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Dragging the third field to the data area. | |
pivotTable.addFieldToArea(PivotFieldType.DATA, 2); | |
// Show grand totals for rows. | |
pivotTable.setRowGrand(true); | |
// Show grand totals for columns. | |
pivotTable.setColumnGrand(true); | |
// Display a custom string in cells that contain null values. | |
pivotTable.setDisplayNullString(true); | |
pivotTable.setNullString("null"); | |
// Setting the layout | |
pivotTable.setPageFieldOrder(PrintOrderType.DOWN_THEN_OVER); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitColumnsinaRangeofCells.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the Column of the worksheet | |
worksheet.autoFitColumn(4, 4, 6); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitColumnsinaRangeofCells_out.xls"); | |
// Print message | |
System.out.println("Columns auto fit successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the 2nd row of the worksheet | |
worksheet.autoFitRow(1); | |
// Auto-fitting the 1st column of the worksheet | |
worksheet.autoFitColumn(0); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Row and Column auto fit successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitRowsinaRangeofCells.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the row of the worksheet | |
worksheet.autoFitRow(1, 0, 5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitRowsinaRangeofCells_out.xls"); | |
// Print message | |
System.out.println("Row auto fit successfully."); |
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
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ConvertTexttoCols.class) + "rows_cloumns/"; | |
//Create a workbook. | |
Workbook wb = new Workbook(); | |
//Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Add people name in column A. Fast name and Last name are separated by space. | |
ws.getCells().get("A1").putValue("John Teal"); | |
ws.getCells().get("A2").putValue("Peter Graham"); | |
ws.getCells().get("A3").putValue("Brady Cortez"); | |
ws.getCells().get("A4").putValue("Mack Nick"); | |
ws.getCells().get("A5").putValue("Hsu Lee"); | |
//Create text load options with space as separator. | |
TxtLoadOptions opts = new TxtLoadOptions(); | |
opts.setSeparator(' '); | |
//Split the column A into two columns using TextToColumns() method. | |
//Now column A will have first name and column B will have second name. | |
ws.getCells().textToColumns(0, 0, 5, opts); | |
//Save the workbook in xlsx format. | |
wb.save(dataDir + "outputTextToColumns.xlsx"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CopyingColumns.class) + "rows_cloumns/"; | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy the first column from the first worksheet of the first workbook into the first worksheet of the second workbook. | |
wsTemplate.getCells().copyColumn(wsTemplate.getCells(), 1, 4); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "CopyingColumns_out.xls"); | |
// Print message | |
System.out.println("Row and Column copied successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CopyingRows.class) + "rows_cloumns/"; | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy the second row with data, formating, images and drawing objects to the 12th row in the worksheet. | |
wsTemplate.getCells().copyRow(wsTemplate.getCells(), 2, 10); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "CopyingRows_out.xls"); | |
// Print message | |
System.out.println("Row and Column copied successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(DeleteAColumn.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Deleting a column from the worksheet at 2nd position | |
worksheet.getCells().deleteColumns(1, 1, true); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "DeleteAColumn_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(DeleteARow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Deleting 3rd row from the worksheet | |
worksheet.getCells().deleteRows(2, 1, true); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "DeleteARow_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(DeleteMultipleRows.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Deleting 10 rows from the worksheet starting from 3rd row | |
worksheet.getCells().deleteRows(2, 10, true); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "DeleteMultipleRows_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(GroupingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by | |
// passing true | |
cells.groupRows(0, 5, true); | |
// Grouping first three columns (from 0 to 2) and making them hidden by | |
// passing true | |
cells.groupColumns(0, 2, true); | |
// Setting SummaryRowBelow property to false | |
worksheet.getOutline().SummaryRowBelow = false; | |
// Setting SummaryColumnRight property to false | |
worksheet.getOutline().SummaryColumnRight = true; | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "GroupingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns grouped successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(HidingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Hiding the 3rd row of the worksheet | |
cells.hideRow(2); | |
// Hiding the 2nd column of the worksheet | |
cells.hideColumn(1); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "HidingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns hidden successfully."); |
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-Java | |
String dataDir = Utils.getSharedDataDir(InsertingAColumn.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Inserting a column into the worksheet at 2nd position | |
worksheet.getCells().insertColumns(1, 1); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "InsertingAColumn_out.xls"); |
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-Java | |
String dataDir = Utils.getSharedDataDir(InsertingARow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Inserting a row into the worksheet at 3rd position | |
worksheet.getCells().insertRows(2, 1); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "InsertingARow_out.xls"); |
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-Java | |
String dataDir = Utils.getSharedDataDir(InsertingMultipleRows.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Inserting 10 rows into the worksheet starting from 3rd row | |
worksheet.getCells().insertRows(2, 10); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "InsertingMultipleRows_out.xls"); |
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-Java | |
// Load some excel file | |
Workbook wb = new Workbook("book1.xlsx"); | |
// Access the first sheet which contains chart | |
Worksheet source = wb.getWorksheets().get(0); | |
// Add another sheet named DestSheet | |
Worksheet destination = wb.getWorksheets().add("DestSheet"); | |
// Set CopyOptions.ReferToDestinationSheet to true | |
CopyOptions options = new CopyOptions(); | |
options.setReferToDestinationSheet(true); | |
// Set PasteOptions | |
PasteOptions pasteOptions = new PasteOptions(); | |
pasteOptions.setPasteType(PasteType.VALUES); | |
pasteOptions.setOnlyVisibleCells(true); | |
// Copy all the rows of source worksheet to destination worksheet which includes chart as well | |
// The chart data source will now refer to DestSheet | |
destination.getCells().copyRows(source.getCells(), 0, 0, source.getCells().getMaxDisplayRange().getRowCount(), options, pasteOptions); | |
// Save workbook in xlsx format | |
wb.save("destination.xlsx", SaveFormat.XLSX); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightAllRows.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of all rows in the worksheet to 15 | |
worksheet.getCells().setStandardHeight(15f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightAllRows_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightOfRow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of the second row to 13 | |
cells.setRowHeight(1, 13); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightOfRow_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfAllColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of all columns in the worksheet to 20.5 | |
worksheet.getCells().setStandardWidth(20.5f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfAllColumns_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfColumn.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of the second column to 17.5 | |
cells.setColumnWidth(1, 17.5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfColumn_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SummaryRowBelow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by passing true | |
cells.groupRows(0, 5, true); | |
// Grouping first three columns (from 0 to 2) and making them hidden by passing true | |
cells.groupColumns(0, 2, true); | |
// Setting SummaryRowBelow property to false | |
worksheet.getOutline().SummaryRowBelow = false; | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SummaryRowBelow_out.xls"); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SummaryRowRight.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "BookStyles.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by passing true | |
cells.ungroupRows(0, 5); | |
// Grouping first three columns (from 0 to 2) and making them hidden by passing true | |
cells.ungroupColumns(0, 2); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SummaryRowRight_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns ungrouped successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(UngroupingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "BookStyles.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by | |
// passing true | |
cells.ungroupRows(0, 5); | |
// Grouping first three columns (from 0 to 2) and making them hidden by | |
// passing true | |
cells.ungroupColumns(0, 2); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "UngroupingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns ungrouped successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(UnhidingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Unhiding the 3rd row and setting its height to 13.5 | |
cells.unhideRow(2, 13.5); | |
// Unhiding the 2nd column and setting its width to 8.5 | |
cells.unhideColumn(1, 8.5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "UnhidingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns unhidden successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AdjustingRowHeightandColumnWidth.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "workbook.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// ============== Setting Row Height ============== | |
// Setting the height of the second row to 40 | |
cells.setRowHeight(1, 40); | |
// Setting the height of all rows in the worksheet to 15 | |
// worksheet.getCells().setStandardHeight(15f); | |
// ============== Setting Column Width ============ | |
// Setting the width of the second column to 17.5 | |
cells.setColumnWidth(1, 50); | |
// Setting the width of all columns in the worksheet to 20.5 | |
// worksheet.getCells().setStandardWidth(20.5f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "workbook.output.xls"); | |
// Print message | |
System.out.println("Height and width modified successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitColumnsinaRangeofCells.class) + "RowsColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "workbook.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the Column of the worksheet | |
worksheet.autoFitColumn(4, 4, 6); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitColumnsinaRangeofCells_out.xls"); | |
// Print message | |
System.out.println("Columns auto fit successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AutoFitRowsandColumns.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "workbook.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the 2nd row of the worksheet | |
worksheet.autoFitRow(1); | |
// Auto-fitting the 1st column of the worksheet | |
worksheet.autoFitColumn(0); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "workbook.out.xls"); | |
// Print message | |
System.out.println("Row and Column auto fit successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AutoFitRowsandColumnsinaRangeofCells.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "workbook.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the 3rd row of the worksheet based on the contents in a range of | |
// cells (from 1st to 9th column) within the row | |
worksheet.autoFitRow(3, 4, 10); | |
// Auto-fitting the 4th column of the worksheet based on the contents in a range of | |
// cells (from 1st to 9th row) within the column | |
worksheet.autoFitColumn(0, 0, 8); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "workbook.out.xls"); | |
// Print message | |
System.out.println("Row and Column auto fit successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AutoFitRowsinaRangeofCells.class) + "RowsColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "workbook.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Auto-fitting the 3rd row of the worksheet | |
worksheet.autoFitRow(2, 0, 5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "AutoFitRowsinaRangeofCells_out.xls"); | |
// Print message | |
System.out.println("Row auto fit successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CopyingColumns.class); | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy the first column from the first worksheet of the first workbook into the first worksheet of the second workbook. | |
wsTemplate.getCells().copyColumn(wsTemplate.getCells(), 1, 4); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "output.xls"); | |
// Print message | |
System.out.println("Column copied successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CopyingRows.class); | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "Book1.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy the second row with data, formating, images and drawing objects to the 12th row in the worksheet. | |
wsTemplate.getCells().copyRow(wsTemplate.getCells(), 2, 10); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "workbook.out.xls"); | |
// Print message | |
System.out.println("Row and Column copied successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CopyingColumns.class) + "RowsColumns/"; | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "workbook.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy the first column from the first worksheet of the first workbook into the first worksheet of the second workbook. | |
wsTemplate.getCells().copyColumn(wsTemplate.getCells(), 1, 1); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "CopyingColumns_out.xls"); | |
// Print message | |
System.out.println("Row and Column copied successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CopyingRows.class) + "RowsColumns/"; | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "workbook.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy row with data, formating, images and drawing objects to another row in the worksheet. | |
wsTemplate.getCells().copyRow(wsTemplate.getCells(), 2, 10); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "CopyingRows_out.xls"); | |
// Print message | |
System.out.println("Row and Column copied successfully."); |
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CopyingRowsandColumns.class); | |
// Create a new Workbook. | |
Workbook excelWorkbook = new Workbook(dataDir + "workbook.xls"); | |
// Get the first worksheet in the workbook. | |
Worksheet wsTemplate = excelWorkbook.getWorksheets().get(0); | |
// Copy the second row with data, formating, images and drawing objects to the 12th row in the worksheet. | |
wsTemplate.getCells().copyRow(wsTemplate.getCells(), 2, 10); | |
// Copy the first column from the first worksheet of the first workbook into the first worksheet of the second workbook. | |
wsTemplate.getCells().copyColumn(wsTemplate.getCells(), 1, 4); | |
// Save the excel file. | |
excelWorkbook.save(dataDir + "workbook.out.xls"); | |
// Print message | |
System.out.println("Row and Column copied successfully."); |
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-Java | |
String dataDir = Utils.getDataDir(DeleteAColumn.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Deleting a column from the worksheet at 2nd position | |
worksheet.getCells().deleteColumns(1, 1, true); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
String dataDir = Utils.getDataDir(DeleteARow.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Deleting 3rd row from the worksheet | |
worksheet.getCells().deleteRows(2, 1, true); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "output.xls"); |
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-Java | |
String dataDir = Utils.getDataDir(DeleteMultipleRows.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Deleting 10 rows from the worksheet starting from 3rd row | |
worksheet.getCells().deleteRows(2, 10, true); | |
// Saving the modified Excel file in default (that is Excel 2000) format | |
workbook.save(dataDir + "output.xls"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment