Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 Gist contains code snippets from examples of Aspose.Cells for Java.
//Create an instance of workbook
Workbook workbook = new Workbook();
//Access first worksheet from the collection
Worksheet worksheet = workbook.getWorksheets().get(0);
//Access cells A1 and A2
Cell a1 = worksheet.getCells().get("A1");
Cell a2 = worksheet.getCells().get("A2");
//Add simple text to cell A1 and text with quote prefix to cell A2
a1.putValue("sample");
a2.putValue("'sample");
//Print their string values, A1 and A2 both are same
System.out.println("String value of A1: " + a1.getStringValue());
System.out.println("String value of A2: " + a2.getStringValue());
//Access styles of cells A1 and A2
Style s1 = a1.getStyle();
Style s2 = a2.getStyle();
System.out.println();
//Check if A1 and A2 has a quote prefix
System.out.println("A1 has a quote prefix: " + s1.getQuotePrefix());
System.out.println("A2 has a quote prefix: " + s2.getQuotePrefix());
public static void main(String[] args) throws Exception {
//The path to the documents directory
String dataDir = Utils.getDataDir(FindReferenceCellsFromExternalConnection.class);
//Load workbook object
Workbook workbook = new Workbook(dataDir + "sample.xlsm");
//Check all the connections inside the workbook
for (int i = 0; i < workbook.getDataConnections().getCount(); i++)
{
ExternalConnection externalConnection = workbook.getDataConnections().get(i);
System.out.println("connection: " + externalConnection.getName());
PrintTables(workbook, externalConnection);
System.out.println();
}
}
public static void PrintTables(Workbook workbook, ExternalConnection ec)
{
//Iterate all the worksheets
for (int j = 0; j < workbook.getWorksheets().getCount(); j++)
{
Worksheet worksheet = workbook.getWorksheets().get(j);
//Check all the query tables in a worksheet
for (int k = 0; k < worksheet.getQueryTables().getCount(); k++)
{
QueryTable qt = worksheet.getQueryTables().get(k);
//Check if query table is related to this external connection
if (ec.getId() == qt.getConnectionId()
&& qt.getConnectionId() >= 0)
{
//Print the query table name and print its "Refers To" range
System.out.println("querytable " + qt.getName());
String n = qt.getName().replace('+', '_').replace('=', '_');
Name name = workbook.getWorksheets().getNames().get("'" + worksheet.getName() + "'!" + n);
if (name != null)
{
Range range = name.getRange();
if (range != null)
{
System.out.println("Refers To: " + range.getRefersTo());
}
}
}
}
//Iterate all the list objects in this worksheet
for (int k = 0; k < worksheet.getListObjects().getCount(); k++)
{
ListObject table = worksheet.getListObjects().get(k);
//Check the data source type if it is query table
if (table.getDataSourceType() == TableDataSourceType.QUERY_TABLE)
{
//Access the query table related to list object
QueryTable qt = table.getQueryTable();
//Check if query table is related to this external connection
if (ec.getId() == qt.getConnectionId()
&& qt.getConnectionId() >= 0)
{
//Print the query table name and print its refersto range
System.out.println("querytable " + qt.getName());
System.out.println("Table " + table.getDisplayName());
System.out.println("refersto: " + worksheet.getName() + "!" + CellsHelper.cellIndexToName(table.getStartRow(), table.getStartColumn()) + ":" + CellsHelper.cellIndexToName(table.getEndRow(), table.getEndColumn()));
}
}
}
}
}//end-PrintTables
public static void main(String[] args) throws Exception {
// The path to the documents directory.
String dataDir = Utils.getDataDir(SmartMarkerGroupingImage.class);
SmartMarkerGroupingImage grouping = new SmartMarkerGroupingImage();
grouping.Execute(dataDir);
}
public void Execute(String dataDir) throws Exception {
//Get the image
Path path = Paths.get(dataDir + "sample1.png");
byte[] photo1 = Files.readAllBytes(path);
//Get the image
path = Paths.get(dataDir + "sample2.jpg");
byte[] photo2 = Files.readAllBytes(path);
//Create a new workbook and access its worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
//Set the standard row height to 35
worksheet.getCells().setStandardHeight(35);
//Set column widhts of D, E and F
worksheet.getCells().setColumnWidth(3, 20);
worksheet.getCells().setColumnWidth(4, 20);
worksheet.getCells().setColumnWidth(5, 40);
//Add the headings in columns D, E and F
worksheet.getCells().get("D1").putValue("Name");
Style st = worksheet.getCells().get("D1").getStyle();
st.getFont().setBold(true);
worksheet.getCells().get("D1").setStyle(st);
worksheet.getCells().get("E1").putValue("City");
worksheet.getCells().get("E1").setStyle(st);
worksheet.getCells().get("F1").putValue("Photo");
worksheet.getCells().get("F1").setStyle(st);
//Add smart marker tags in columns D, E, F
worksheet.getCells().get("D2").putValue("&=Person.Name(group:normal,skip:1)");
worksheet.getCells().get("E2").putValue("&=Person.City");
worksheet.getCells().get("F2").putValue("&=Person.Photo(Picture:FitToCell)");
//Create Persons objects with photos
ArrayList<Person> persons = new ArrayList<Person>();
persons.add(new Person("George", "New York", photo1));
persons.add(new Person("George", "New York", photo2));
persons.add(new Person("George", "New York", photo1));
persons.add(new Person("George", "New York", photo2));
persons.add(new Person("Johnson", "London", photo2));
persons.add(new Person("Johnson", "London", photo1));
persons.add(new Person("Johnson", "London", photo2));
persons.add(new Person("Simon", "Paris", photo1));
persons.add(new Person("Simon", "Paris", photo2));
persons.add(new Person("Simon", "Paris", photo1));
persons.add(new Person("Henry", "Sydney", photo2));
persons.add(new Person("Henry", "Sydney", photo1));
persons.add(new Person("Henry", "Sydney", photo2));
//Create a workbook designer
WorkbookDesigner designer = new WorkbookDesigner(workbook);
//Set the data source and process smart marker tags
designer.setDataSource("Person", persons);
designer.process();
//Save the workbook
workbook.save(dataDir + "output.xlsx", SaveFormat.XLSX);
System.out.println("File saved");
}
public class Person
{
//Create Name, City and Photo properties
private String m_Name;
private String m_City;
private byte[] m_Photo;
public Person(String name, String city, byte[] photo)
{
m_Name = name;
m_City = city;
m_Photo = photo;
}
public String getName() { return this.m_Name; }
public void setName(String name) { this.m_Name = name; }
public String getCity() { return this.m_City; }
public void setCity(String address) { this.m_City = address; }
public byte[] getPhoto() { return this.m_Photo; }
public void setAddress(byte[] photo) { this.m_Photo = photo; }
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load sample Excel file containing the chart.
Workbook wb = new Workbook(srcDir + "sampleCreateChartPDFWithDesiredPageSize.xlsx");
//Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
//Access first chart inside the worksheet.
Chart ch = ws.getCharts().get(0);
//Create chart pdf with desired page size.
ch.toPdf(outDir + "outputCreateChartPDFWithDesiredPageSize.pdf", 7, 7, PageLayoutAlignmentType.CENTER, PageLayoutAlignmentType.CENTER);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Converting integer enums to string enums
java.util.HashMap<Integer, String> cvTypes = new java.util.HashMap<Integer, String>();
cvTypes.put(CellValueType.IS_NUMERIC, "IsNumeric");
cvTypes.put(CellValueType.IS_STRING, "IsString");
//Load sample Excel file containing chart.
Workbook wb = new Workbook(srcDir + "sampleFindTypeOfXandYValuesOfPointsInChartSeries.xlsx");
//Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
//Access first chart.
Chart ch = ws.getCharts().get(0);
//Calculate chart data.
ch.calculate();
//Access first chart point in the first series.
ChartPoint pnt = ch.getNSeries().get(0).getPoints().get(0);
//Print the types of X and Y values of chart point.
System.out.println("X Value Type: " + cvTypes.get(pnt.getXValueType()));
System.out.println("Y Value Type: " + cvTypes.get(pnt.getYValueType()));
// 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("sampleHandleAutomaticUnitsOfChartAxisLikeMicrosoftExcel.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first chart
Chart ch = ws.getCharts().get(0);
//Render chart to pdf
ch.toPdf("outputHandleAutomaticUnitsOfChartAxisLikeMicrosoftExcel.pdf");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the Excel file containing chart
Workbook wb = new Workbook("sampleReadAxisLabelsAfterCalculatingTheChart.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access the chart
Chart ch = ws.getCharts().get(0);
//Calculate the chart
ch.calculate();
//Read axis labels of category axis
ArrayList lstLabels = ch.getCategoryAxis().getAxisLabels();
//Print axis labels on console
System.out.println("Category Axis Labels: ");
System.out.println("---------------------");
//Iterate axis labels and print them one by one
for(int i=0; i<lstLabels.size(); i++)
{
System.out.println(lstLabels.get(i));
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load source Excel file
Workbook wb = new Workbook("sampleSetShapeTypeOfDataLabelsOfChart.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first chart
Chart ch = ws.getCharts().get(0);
//Access first series
Series srs = ch.getNSeries().get(0);
//Set the shape type of data labels i.e. Speech Bubble Oval
srs.getDataLabels().setShapeType(DataLabelShapeType.WEDGE_ELLIPSE_CALLOUT);
//Save the output Excel file
wb.save("outputSetShapeTypeOfDataLabelsOfChart.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Load sample Excel file containing cells with formatting.
Workbook wb = new Workbook(srcDir + "sampleChangeCellsAlignmentAndKeepExistingFormatting.xlsx");
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Create cells range.
Range rng = ws.getCells().createRange("B2:D7");
// Create style object.
Style st = wb.createStyle();
// Set the horizontal and vertical alignment to center.
st.setHorizontalAlignment(TextAlignmentType.CENTER);
st.setVerticalAlignment(TextAlignmentType.CENTER);
// Create style flag object.
StyleFlag flag = new StyleFlag();
// Set style flag alignments true. It is most crucial statement.
// Because if it will be false, no changes will take place.
flag.setAlignments(true);
// Apply style to range of cells.
rng.applyStyle(st, flag);
// Save the workbook in XLSX format.
wb.save(outDir + "outputChangeCellsAlignmentAndKeepExistingFormatting.xlsx", SaveFormat.XLSX);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create empty workbook.
Workbook wb = new Workbook();
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Create range A1:B3.
System.out.println("Creating Range A1:B3\n");
Range rng = ws.getCells().createRange("A1:B3");
// Print range address and cell count.
System.out.println("Range Address: " + rng.getAddress());
System.out.println("Cell Count: " + rng.getCellCount());
// Formatting console output.
System.out.println("----------------------");
System.out.println("");
// Create range A1.
System.out.println("Creating Range A1\n");
rng = ws.getCells().createRange("A1");
// Print range offset, entire column and entire row.
System.out.println("Offset: " + rng.getOffset(2, 2).getAddress());
System.out.println("Entire Column: " + rng.getEntireColumn().getAddress());
System.out.println("Entire Row: " + rng.getEntireRow().getAddress());
// Formatting console output.
System.out.println("----------------------");
System.out.println("");
// 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 + "sampleGetAllHiddenRowsIndicesAfterRefreshingAutoFilter.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Apply autofilter
ws.getAutoFilter().addFilter(0, "Orange");
//True means, it will refresh autofilter and return hidden rows.
//False means, it will not refresh autofilter but return same hidden rows.
int[] rowIndices = ws.getAutoFilter().refresh(true);
System.out.println("Printing Rows Indices, Cell Names and Values Hidden By AutoFilter.");
System.out.println("--------------------------");
for(int i=0; i<rowIndices.length; i++)
{
int r = rowIndices[i];
Cell cell = ws.getCells().get(r, 0);
System.out.println(r + "\t" + cell.getName() + "\t" + cell.getStringValue());
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Create workbook
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access cell A1
Cell cell = ws.getCells().get("A1");
//Put some text in cell, it does not have Single Quote at the beginning
cell.putValue("Text");
//Access style of cell A1
Style st = cell.getStyle();
//Print the value of Style.QuotePrefix of cell A1
System.out.println("Quote Prefix of Cell A1: " + st.getQuotePrefix());
//Put some text in cell, it has Single Quote at the beginning
cell.putValue("'Text");
//Access style of cell A1
st = cell.getStyle();
//Print the value of Style.QuotePrefix of cell A1
System.out.println("Quote Prefix of Cell A1: " + st.getQuotePrefix());
//Print information about StyleFlag.QuotePrefix property
System.out.println();
System.out.println("When StyleFlag.QuotePrefix is False, it means, do not update the value of Cell.Style.QuotePrefix.");
System.out.println("Similarly, when StyleFlag.QuotePrefix is True, it means, update the value of Cell.Style.QuotePrefix.");
System.out.println();
//Create an empty style
st = wb.createStyle();
//Create style flag - set StyleFlag.QuotePrefix as false
//It means, we do not want to update the Style.QuotePrefix property of cell A1's style.
StyleFlag flag = new StyleFlag();
flag.setQuotePrefix(false);
//Create a range consisting of single cell A1
Range rng = ws.getCells().createRange("A1");
//Apply the style to the range
rng.applyStyle(st, flag);
//Access the style of cell A1
st = cell.getStyle();
//Print the value of Style.QuotePrefix of cell A1
//It will print True, because we have not updated the Style.QuotePrefix property of cell A1's style.
System.out.println("Quote Prefix of Cell A1: " + st.getQuotePrefix());
//Create an empty style
st = wb.createStyle();
//Create style flag - set StyleFlag.QuotePrefix as true
//It means, we want to update the Style.QuotePrefix property of cell A1's style.
flag = new StyleFlag();
flag.setQuotePrefix(true);
//Apply the style to the range
rng.applyStyle(st, flag);
//Access the style of cell A1
st = cell.getStyle();
//Print the value of Style.QuotePrefix of cell A1
//It will print False, because we have updated the Style.QuotePrefix property of cell A1's style.
System.out.println("Quote Prefix of Cell A1: " + st.getQuotePrefix());
// 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.*;
import AsposeCellsExamples.Utils;
public class SpecifyFormulaFieldsWhileImportingDataToWorksheet {
static String outDir = Utils.Get_OutputDirectory();
//User-defined class to hold data items
public class DataItems
{
private int m_Number1;
private int m_Number2;
private String m_Formula1;
private String m_Formula2;
public DataItems(int num1, int num2, String form1, String form2)
{
this.m_Number1 = num1;
this.m_Number2 = num2;
this.m_Formula1 = form1;
this.m_Formula2 = form2;
}
public int getNumber1()
{
return this.m_Number1;
}
public int getNumber2()
{
return this.m_Number2;
}
public String getFormula1()
{
return this.m_Formula1;
}
public String getFormula2()
{
return this.m_Formula2;
}
}//DataItems
public void Run() throws Exception
{
System.out.println("Aspose.Cells for Java Version: " + CellsHelper.getVersion());
//List to hold data items
ArrayList<DataItems> dis = new ArrayList<DataItems>();
//Define 1st data item and add it in list
int num1 = 2002;
int num2 = 3502;
String form1 = "=SUM(A2,B2)";
String form2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")";
DataItems di = new DataItems(num1, num2, form1, form2);
dis.add(di);
//Define 2nd data item and add it in list
num1 = 2003;
num2 = 3503;
form1 = "=SUM(A3,B3)";
form2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")";
di = new DataItems(num1, num2, form1, form2);
dis.add(di);
//Define 3rd data item and add it in list
num1 = 2004;
num2 = 3504;
form1 = "=SUM(A4,B4)";
form2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")";
di = new DataItems(num1, num2, form1, form2);
dis.add(di);
//Define 4th data item and add it in list
num1 = 2005;
num2 = 3505;
form1 = "=SUM(A5,B5)";
form2 = "=HYPERLINK(\"https://www.aspose.com\",\"Aspose Website\")";
di = new DataItems(num1, num2, form1, form2);
dis.add(di);
//Create workbook object
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Specify import table options
ImportTableOptions opts = new ImportTableOptions();
//Specify which field is formula field, here the last two fields are formula fields
//opts.setColumnIndexes(new int[] {3, 0, 2, 1});
opts.setFormulas(new boolean[] {false, false, true, true });
//Import custom objects
ws.getCells().importCustomObjects(dis, 0, 0, opts);
//Calculate formula
wb.calculateFormula();
//Autofit columns
ws.autoFitColumns();
//Save the output Excel file
wb.save(outDir + "outputSpecifyFormulaFieldsWhileImportingDataToWorksheet.xlsx");
// Print the message
System.out.println("SpecifyFormulaFieldsWhileImportingDataToWorksheet executed successfully.");
}
public static void main(String[] args) throws Exception {
new SpecifyFormulaFieldsWhileImportingDataToWorksheet().Run();
}
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Create workbook object.
Workbook wb = new Workbook();
//Access built-in document property collection.
BuiltInDocumentPropertyCollection bdpc = wb.getBuiltInDocumentProperties();
//Set the language of the Excel file.
bdpc.setLanguage("German, French");
//Save the workbook in xlsx format.
wb.save(outDir + "outputSpecifyLanguageOfExcelFileUsingBuiltInDocumentProperties.xlsx", SaveFormat.XLSX);
// 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("sampleAccessAndModifyLabelOfOleObject.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first Ole Object
OleObject oleObject = ws.getOleObjects().get(0);
//Display the Label of the Ole Object
System.out.println("Ole Object Label - Before: " + oleObject.getLabel());
//Modify the Label of the Ole Object
oleObject.setLabel("Aspose APIs");
//Save workbook to byte array output stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
wb.save(baos, SaveFormat.XLSX);
//Convert output to input stream
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
//Set the workbook reference to null
wb = null;
//Load workbook from byte array input stream
wb = new Workbook(bais);
//Access first worksheet
ws = wb.getWorksheets().get(0);
//Access first Ole Object
oleObject = ws.getOleObjects().get(0);
//Display the Label of the Ole Object that has been modified earlier
System.out.println("Ole Object Label - After: " + oleObject.getLabel());
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Load sample Excel file containing gear type smart art shape.
Workbook wb = new Workbook(srcDir + "sampleExtractTextFromGearTypeSmartArtShape.xlsx");
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Access first shape.
Shape sh = ws.getShapes().get(0);
// Get the result of gear type smart art shape in the form of group shape.
GroupShape gs = sh.getResultOfSmartArt();
// Get the list of individual shapes consisting of group shape.
Shape[] shps = gs.getGroupedShapes();
// Extract the text of gear type shapes and print them on console.
for (int i = 0; i < shps.length; i++)
{
Shape s = shps[i];
if (s.getType() == AutoShapeType.GEAR_9 || s.getType() == AutoShapeType.GEAR_6)
{
System.out.println("Gear Type Shape Text: " + s.getText());
}
}//for
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load sample Excel file.
Workbook wb = new Workbook(srcDir + "sampleRotateTextWithShapeInsideWorksheet.xlsx");
//Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
//Access cell B4 and add message inside it.
Cell b4 = ws.getCells().get("B4");
b4.putValue("Text is not rotating with shape because RotateTextWithShape is false.");
//Access first shape.
Shape sh = ws.getShapes().get(0);
//Access shape text alignment.
ShapeTextAlignment shapeTextAlignment = sh.getTextBody().getTextAlignment();
//Do not rotate text with shape by setting RotateTextWithShape as false.
shapeTextAlignment.setRotateTextWithShape(false);
//Save the output Excel file.
wb.save(outDir + "outputRotateTextWithShapeInsideWorksheet.xlsx");
// 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("sampleSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
for(int idx =0; idx<ws.getShapes().getCount(); idx++)
{
//Access the shape
Shape sh = ws.getShapes().get(idx);
//Access the text alignment
ShapeTextAlignment txtAlign = sh.getTextBody().getTextAlignment();
//Set auto margin false
txtAlign.setAutoMargin(false);
//Set the top, left, bottom and right margins
txtAlign.setTopMarginPt(10);
txtAlign.setLeftMarginPt(10);
txtAlign.setBottomMarginPt(10);
txtAlign.setRightMarginPt(10);
}
//Save the output Excel file
wb.save("outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create empty workbook.
Workbook wb = new Workbook();
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Add textbox inside the worksheet.
int idx = ws.getTextBoxes().add(5, 5, 50, 200);
TextBox tb = ws.getTextBoxes().get(idx);
// Set the text of the textbox.
tb.setText("こんにちは世界");
// Specify the Far East and Latin name of the font.
tb.getTextOptions().setLatinName("Comic Sans MS");
tb.getTextOptions().setFarEastName("KaiTi");
// Save the output Excel file.
wb.save("outputSpecifyFarEastAndLatinNameOfFontInTextOptionsOfShape.xlsx", SaveFormat.XLSX);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Access first worksheet of gridweb
GridWorksheet sheet = gridweb.getWorkSheets().get(0);
// Access cell A1
GridCell cell = sheet.getCells().get("A1");
// Access hyperlink of cell A1 if it contains any
GridHyperlink lnk = sheet.getHyperlinks().getHyperlink(cell);
if (lnk == null) {
// This cell does not have any hyperlink
} else {
// This cell does have hyperlink, access its properties e.g. address
String addr = lnk.getAddress();
}
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Accessing "B1" cell of the worksheet
GridCell cell = sheet.getCells().get("B1");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Accessing "B1" cell of the worksheet using its row and column indices
GridCell cell = sheet.getCells().get(0, 1);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Accessing "B1" cell of the worksheet
GridCell cell = sheet.getCells().get("B1");
//Putting a value in "B1" cell
cell.putValue(Calendar.getInstance());
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Accessing "B1" cell of the worksheet
GridCell cell = sheet.getCells().get("B1");
//Putting a numeric value as string in "B1" cell that will be converted to a suitable data type automatically
cell.putValue("19.4", true);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Accessing "B1" cell of the worksheet
GridCell cell = sheet.getCells().get("B1");
//Inserting & modifying the string value of "B1" cell
cell.putValue("Hello Aspose.Grid");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Putting some values to cells
sheet.getCells().get("A1").putValue("1st Value");
sheet.getCells().get("A2").putValue("2nd Value");
sheet.getCells().get("A3").putValue("Sum");
sheet.getCells().get("B1").putValue(125.56);
sheet.getCells().get("B2").putValue(23.93);
//Calculating all formulas added in worksheets
gridweb.getWorkSheets().calculateFormula();
//Adding a simple formula to "B3" cell
sheet.getCells().get("B3").setFormula("=SUM(B1:B2)");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Calculating all formulas added in worksheets
gridweb.getWorkSheets().calculateFormula();
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Access first worksheet
GridWorksheet sheet = gridweb.getWorkSheets().get(0);
//Access cell B3
GridCell cell = sheet.getCells().get("B3");
//Add validation inside the gridcell
//Any value which is not between 20 and 40 will cause error in a gridcell
GridValidation val = cell.createValidation(GridValidationType.WHOLE_NUMBER, true);
val.setFormula1("=20");
val.setFormula2("=40");
val.setOperator(OperatorType.BETWEEN);
val.setShowError(true);
val.setShowInput(true);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Instantiating a CustomCommandButton object
CustomCommandButton button = new CustomCommandButton();
//Setting the command for button
button.setCommand("MyButton");
//Setting text of the button
button.setText("MyButton");
//Setting tooltip of the button
button.setToolTip("My Custom Command Button");
//Setting image URL of the button
button.setImageUrl("icon.png");
//Adding button to CustomCommandButtons collection of GridWeb
gridweb.getCustomCommandButtons().add(button);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Access cell A1 of first gridweb worksheet
GridCell cellA1 = gridweb.getWorkSheets().get(0).getCells().get("A1");
//Access cell style and set its number format to 10 which is a Percentage 0.00% format
GridTableItemStyle st = cellA1.getStyle();
st.setNumberType(10);
cellA1.setStyle(st);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Create custom command event handler to handle the click event
CustomCommandEventHandler cceh=new CustomCommandEventHandler(){
public void handleCellEvent(Object sender, String command){
//Identifying a specific button by checking its command
if (command.equals("MyButton"))
{
//Accessing the cells collection of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Putting value to "A1" cell
sheet.getCells().get("A1").putValue("My Custom Command Button is Clicked.");
sheet.getCells().setColumnWidth(0, 50);
}
}
};
//Assign the custom command event handler created above to gridweb
gridweb.CustomCommand = cceh;
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet of the Grid that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Adding a bit complex formula to "A1" cell
sheet.getCells().get("A1").setFormula("=SUM(F1:F7)/ AVERAGE (E1:E7)-Sheet1!C6");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Setting the height of GridWeb control
gridweb.setHeight(Unit.Point(200));
//Setting the width of GridWeb control
gridweb.setWidth(Unit.Point(520));
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Setting the height of header bar
gridweb.setHeaderBarHeight(Unit.Point(35));
//Setting the width of header bar
gridweb.setHeaderBarWidth(Unit.Point(50));
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
int presetStyle = PresetStyle.COLORFUL_1;
gridweb.setPresetStyle(presetStyle);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String customFilePath = "http://localhost:8080/GDemo/xml/CustomStyle1.xml";
int presetStyle = PresetStyle.CUSTOM;
gridweb.setCustomStyleFileName(customFilePath);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
CellEventHandler ce = new CellEventHandler() {
public void handleCellEvent(Object sender, CellEventArgs e) {
System.out.println("Cell " + e.getCell().getName() + " is double-clicked.");
}
};
gridweb.CellDoubleClick = ce;
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Event Handler for ColumnDoubleClick event
RowColumnEventHandler re = new RowColumnEventHandler() {
public void handleCellEvent(Object sender, RowColumnEventArgs e) {
System.out.println("Column header:" + (e.getNum() + 1) + " is double-clicked.");
}
};
gridweb.ColumnDoubleClick = re;
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Event Handler for RowDoubleClick event
RowColumnEventHandler re = new RowColumnEventHandler() {
public void handleCellEvent(Object sender, RowColumnEventArgs e) {
System.out.println("Row header:" + (e.getNum() + 1) + " is double-clicked.");
}
};
gridweb.RowDoubleClick = re;
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Enabling Double Click events
gridweb.setEnableDoubleClickEvent(true);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Enabling the Edit Mode of GridWeb
gridweb.setEditMode(true);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Enabling the View Mode of GridWeb
gridweb.setEditMode(false);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
CellEventHandler ce = new CellEventHandler() {
public void handleCellEvent(Object sender, CellEventArgs e) {
//Your event handler code goes here
if (e.getArgument().toString().equals("A1")) {
//Your rest of the code
}
}
};
gridweb.CellCommand = ce;
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Setting the background color of the header bars
gridweb.getHeaderBarStyle().setBackColor(Color.getBrown());
//Setting the foreground color of the header bars
gridweb.getHeaderBarStyle().setForeColor(Color.getYellow());
//Setting the font of the header bars to bold
gridweb.getHeaderBarStyle().getFont().setBold(true);
//Setting the font name to "Century Gothic"
gridweb.getHeaderBarStyle().getFont().setName("Century Gothic");
//Setting the border width to 2 points
gridweb.getHeaderBarStyle().setBorderWidth(Unit.Point(2));
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Specifying the path of Excel file using importExcelFile method of the control
gridweb.importExcelFile(filePath);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Printing Grid web
gridweb.print();
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Saving Grid content to an Excel file
gridweb.saveToExcelFile("/new.xlsx");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Setting the background color of tabs to Yellow
gridweb.getTabStyle().setBackColor(Color.getYellow());
//Setting the foreground color of tabs to Blue
gridweb.getTabStyle().setForeColor(Color.getBlue());
//Setting the background color of active tab to Blue
gridweb.getActiveTabStyle().setBackColor(Color.getBlue());
//Setting the foreground color of active tab to Yellow
gridweb.getActiveTabStyle().setForeColor(Color.getYellow());
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet that is currently active
GridWorksheet worksheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Setting the header of 1st column to "ID"
worksheet.SetColumnCaption(0, "ID");
//Setting the header of 2nd column to "Name"
worksheet.SetColumnCaption(1, "Name");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the worksheet that is currently active
GridWorksheet worksheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Setting the header of 1st row to "ID"
worksheet.setRowCaption(1, "ID");
//Setting the header of 2nd row to "Name"
worksheet.setRowCaption(2, "Name");
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Deleting 2nd column from the worksheet
sheet.getCells().deleteColumn(1);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Deleting 2nd row from the worksheet
sheet.getCells().deleteRow(1);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Freezing 4th row and 3rd column
sheet.freezePanes(3, 2, 3, 2);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Inserting a new column to the worksheet before column "B"
sheet.getCells().insertColumn(1);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Inserting a new row to the worksheet before 2nd row
sheet.getCells().insertRow(1);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the first worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Restricting column related operations in context menu
gridweb.setEnableClientColumnOperations(false);
//Restricting row related operations in context menu
gridweb.setEnableClientRowOperations(false);
//Restricting freeze option of context menu
gridweb.setEnableClientFreeze(false);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the cells collection of the worksheet that is currently active
GridCells cells = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex()).getCells();
//Setting the width of 1st column to 150 points
cells.setColumnWidth(0, 150);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the cells collection of the worksheet that is currently active
GridCells cells = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex()).getCells();
//Setting the height of 1st row to 50 points
cells.setRowHeight(0, 50);
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = gridweb.getWorkSheets().get(gridweb.getActiveSheetIndex());
//Unfreezing rows and columns
sheet.unFreezePanes();
For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
WorkbookEventHandler we=new WorkbookEventHandler(){
public void handleCellEvent(Object sender, CellEventArgs e){
System.out.println("----------Save Command----------");
}
};
CellEventHandler ceh=new CellEventHandler(){
public void handleCellEvent(Object sender, CellEventArgs e){
System.out.println("---------Cell Double Click---------");
}
};
RowColumnEventHandler reh=new RowColumnEventHandler(){
public void handleCellEvent(Object sender, RowColumnEventArgs e){
System.out.println("----------Row Double Click---------------");
}
};
RowColumnEventHandler cdbclick=new RowColumnEventHandler(){
public void handleCellEvent(Object sender, RowColumnEventArgs e){
System.out.println("----------Column Double Click-------------");
}
};
gridweb.setEnableDoubleClickEvent(true);
gridweb.SaveCommand=we;
gridweb.CellDoubleClick=ceh;
gridweb.RowDoubleClick=reh;
gridweb.ColumnDoubleClick=cdbclick;
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the source Excel file
Workbook wb = new Workbook("sampleSeries_ValuesFormatCode.xlsx");
//Access first worksheet
Worksheet worksheet = wb.getWorksheets().get(0);
//Access first chart
Chart ch = worksheet.getCharts().get(0);
//Add series using an array of values
ch.getNSeries().add("{10000, 20000, 30000, 40000}", true);
//Access the series and set its values format code
Series srs = ch.getNSeries().get(0);
srs.setValuesFormatCode("$#,##0");
//Save the output Excel file
wb.save("outputSeries_ValuesFormatCode.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Load your source workbook
Workbook wb = new Workbook(srcDir + "sampleAdvancedFilter.xlsx");
// Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
// Apply advanced filter on range A5:D19 and criteria range is A1:D2
// Besides, we want to filter in place
// And, we want all filtered records not just unique records
ws.advancedFilter(true, "A5:D19", "A1:D2", "", false);
// Save the workbook in xlsx format
wb.save(outDir + "outputAdvancedFilter.xlsx", SaveFormat.XLSX);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create Connection object - connect to Microsoft Access Students Database
java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:ucanaccess://" + srcDir + "Students.accdb");
// Create SQL Statement with Connection object
java.sql.Statement st = conn.createStatement();
// Execute SQL Query and obtain ResultSet
java.sql.ResultSet rs = st.executeQuery("SELECT * FROM Student");
// Create workbook object
Workbook wb = new Workbook();
// Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
// Access cells collection
Cells cells = ws.getCells();
// Create import table options
ImportTableOptions options = new ImportTableOptions();
// Import Result Set at (row=2, column=2)
cells.importResultSet(rs, 2, 2, options);
// Execute SQL Query and obtain ResultSet again
rs = st.executeQuery("SELECT * FROM Student");
// Import Result Set at cell G10
cells.importResultSet(rs, "G10", options);
// Autofit columns
ws.autoFitColumns();
// Save the workbook
wb.save(outDir + "outputImportResultSet.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
public class ShiftFirstRowDownWhenInsertingCellsDataTableRows {
class CellsDataTable implements ICellsDataTable
{
//This is the current row index
int m_index=-1;
//These are your column names
String[] colsNames = new String[] { "Pet", "Fruit", "Country", "Color" };
//These are the data of each column
String[] col0data = new String[] { "Dog", "Cat", "Duck" };
String[] col1data = new String[] { "Apple", "Pear", "Banana" };
String[] col2data = new String[] { "UK", "USA", "China" };
String[] col3data = new String[] { "Red", "Green", "Blue" };
//Combine all of the data into a single two dimensional array
String[][] colsData = new String[][]{ col0data, col1data, col2data, col3data};
public void beforeFirst() {
m_index = -1;
}
public Object get(int columnIndex) {
Object o = null;
o = colsData[columnIndex][m_index];
return o;
}
public Object get(String columnName) {
return null;
}
public String[] getColumns() {
return colsNames;
}
public int getCount() {
return col0data.length;
}
public boolean next() {
m_index++;
return true;
}
}//End Class - CellsDataTable
public void Run() throws Exception
{
String srcDir = Utils.Get_SourceDirectory();
String outDir = Utils.Get_OutputDirectory();
//Create the instance of Cells Data Table
CellsDataTable cellsDataTable = new CellsDataTable();
//Load the sample workbook
Workbook wb = new Workbook(srcDir + "sampleImportTableOptionsShiftFirstRowDown.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Import data table options
ImportTableOptions opts = new ImportTableOptions();
//We do now want to shift the first row down when inserting rows.
opts.setShiftFirstRowDown(false);
//Import cells data table
ws.getCells().importData(cellsDataTable, 2, 2, opts);
//Save the workbook
wb.save(outDir + "outputImportTableOptionsShiftFirstRowDown-False.xlsx");
}
public static void main(String[] args) throws Exception {
ShiftFirstRowDownWhenInsertingCellsDataTableRows pg = new ShiftFirstRowDownWhenInsertingCellsDataTableRows();
pg.Run();
}
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the source Excel file
Workbook wb = new Workbook(srcDir + "sampleSortData_CustomSortList.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Specify cell area - sort from A1 to A40
CellArea ca = CellArea.createCellArea("A1", "A40");
//Create Custom Sort list
String[] customSortList = new String[] { "USA,US", "Brazil,BR", "China,CN", "Russia,RU", "Canada,CA" };
//Add Key for Column A, Sort it in Ascending Order with Custom Sort List
wb.getDataSorter().addKey(0, SortOrder.ASCENDING, customSortList);
wb.getDataSorter().sort(ws.getCells(), ca);
//Save the output Excel file
wb.save(outDir + "outputSortData_CustomSortList.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the sample smart art shape - Excel file
Workbook wb = new Workbook("sampleSmartArtShape_GetResultOfSmartArt.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first shape
Shape sh = ws.getShapes().get(0);
//Determine if shape is smart art
System.out.println("Is Smart Art Shape: " + sh.isSmartArt());
//Determine if shape is group shape
System.out.println("Is Group Shape: " + sh.isGroup());
//Convert smart art shape into group shape
System.out.println("Is Group Shape: " + sh.getResultOfSmartArt().isGroup());
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load the sample smart art shape - Excel file
Workbook wb = new Workbook("sampleSmartArtShape.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first shape
Shape sh = ws.getShapes().get(0);
//Determine if shape is smart art
System.out.println("Is Smart Art Shape: " + sh.isSmartArt());
// 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(NonPrimitiveShape.class) + "DrawingObjects/";
Workbook workbook = new Workbook(dataDir + "NonPrimitiveShape.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
// Accessing the user defined shape
Shape shape = worksheet.getShapes().get(0);
if (shape.getAutoShapeType() == AutoShapeType.NOT_PRIMITIVE) {
// Access Shape paths
ShapePathCollection shapePathCollection = shape.getPaths();
// Access information of individual shape path
ShapePath shapePath = shapePathCollection.get(0);
// Access shape segment path list
ShapeSegmentPathCollection shapeSegmentPathCollection = shapePath.getPathSegementList();
// Access individual segment path
ShapeSegmentPath shapeSegmentPath = shapeSegmentPathCollection.get(0);
ShapePathPointCollection segmentPoints = shapeSegmentPath.getPoints();
for (Object obj : segmentPoints) {
ShapePathPoint pathPoint = (ShapePathPoint) obj;
System.out.println("X: " + pathPoint.getX() + ", Y: " + pathPoint.getY());
}
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load source Excel file
Workbook wb = new Workbook(srcDir + "sampleToFrontOrBack.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first and fourth shape
Shape sh1 = ws.getShapes().get(0);
Shape sh4 = ws.getShapes().get(3);
//Print the Z-Order position of the shape
System.out.println("Z-Order Shape 1: " + sh1.getZOrderPosition());
//Send this shape to front
sh1.toFrontOrBack(2);
//Print the Z-Order position of the shape
System.out.println("Z-Order Shape 4: " + sh4.getZOrderPosition());
//Send this shape to back
sh4.toFrontOrBack(-2);
//Save the output Excel file
wb.save(outDir + "outputToFrontOrBack.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load sample Excel file
Workbook wb = new Workbook(srcDir + "sampleTextureFill_IsTiling.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first shape inside the worksheet
Shape sh = ws.getShapes().get(0);
//Tile Picture as a Texture inside the Shape
sh.getFill().getTextureFill().setTiling(true);
//Save the output Excel file
wb.save(outDir + "outputTextureFill_IsTiling.xlsx");
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Open an Excel file.
Workbook workbook = new Workbook(srcDir + "sampleSetDefaultFontPropertyOfPdfSaveOptionsAndImageOrPrintOptions.xlsx");
// Rendering to PNG file format while setting the
// CheckWorkbookDefaultFont attribue to false.
// So, "Times New Roman" font would be used for any missing (not
// installed) font in the workbook.
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.setImageFormat(ImageFormat.getPng());
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 attribue to false.
// So, "Times New Roman" font would be used for any missing (not
// installed) font in the workbook.
imgOpt.setImageFormat(ImageFormat.getTiff());
WorkbookRender wr = new WorkbookRender(workbook, imgOpt);
wr.toImage(outDir + "outputSetDefaultFontProperty_ImageTIFF.tiff");
// Rendering to PDF file format while setting the
// CheckWorkbookDefaultFont attribue 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);
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Implement calculation monitor class
class clsCalculationMonitor extends AbstractCalculationMonitor
{
public void beforeCalculate(int sheetIndex, int rowIndex, int colIndex)
{
//Find the cell name
String cellName = CellsHelper.cellIndexToName(rowIndex, colIndex);
//Print the sheet, row and column index as well as cell name
System.out.println(sheetIndex + "----" + rowIndex + "----" + colIndex + "----" + cellName);
//If cell name is B8, interrupt/cancel the formula calculation
if (cellName.equals("B8") == true)
{
this.interrupt("Interrupt/Cancel the formula calculation");
}//if
}//beforeCalculate
}//clsCalculationMonitor
//---------------------------------------------------------
//---------------------------------------------------------
public void Run() throws Exception
{
//Load the sample Excel file
Workbook wb = new Workbook(srcDir + "sampleCalculationMonitor.xlsx");
//Create calculation options and assign instance of calculation monitor class
CalculationOptions opts = new CalculationOptions();
opts.setCalculationMonitor(new clsCalculationMonitor());
//Calculate formula with calculation options
wb.calculateFormula(opts);
}
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Create workbook object
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access cell B5 and add some message inside it
Cell cell = ws.getCells().get("B5");
cell.putValue("This PDF format is compatible with PDFA-1a.");
//Create pdf save options and set its compliance to PDFA-1a
PdfSaveOptions opts = new PdfSaveOptions();
opts.setCompliance(PdfCompliance.PDF_A_1_A);
//Save the output pdf
wb.save(dataDir + "outputCompliancePdfA1a.pdf", opts);