本文整理汇总了Java中com.aspose.cells.Cells类的典型用法代码示例。如果您正苦于以下问题:Java Cells类的具体用法?Java Cells怎么用?Java Cells使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cells类属于com.aspose.cells包,在下文中一共展示了Cells类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
//Instantiate a new workbook
Workbook workbook = new Workbook("data/book1.xls");
//Get the Cells collection in the first worksheet
Cells cells = workbook.getWorksheets().get(0).getCells();
//Create a cellarea i.e.., B3:C19
CellArea ca = new CellArea();
ca.StartRow = 2;
ca.StartColumn =1;
ca.EndRow = 18;
ca.EndColumn = 2;
//Apply subtotal, the consolidation function is Sum and it will applied to
//Second column (C) in the list
cells.subtotal(ca, 0, ConsolidationFunction.SUM, new int[] { 1 });
//Save the excel file
workbook.save("data/AsposeTotal.xls");
// Print message
System.out.println("Process completed successfully");
}
示例2: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
//Instantiating a Workbook object
Workbook workbook = new Workbook("data/workbook.xls");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
//Finding the cell containing the specified formula
Cells cells = worksheet.getCells();
//Instantiate FindOptions
FindOptions findOptions = new FindOptions();
//Finding the cell containing a string value that starts with "Or"
findOptions.setLookAtType(LookAtType.START_WITH);
Cell cell = cells.find("SH",null,findOptions);
//Printing the name of the cell found after searching worksheet
System.out.println("Name of the cell containing String: " + cell.getName());
}
示例3: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/mergecells/data/";
//Create a Workbook.
Workbook wbk = new Workbook();
//Create a Worksheet and get the first sheet.
Worksheet worksheet = wbk.getWorksheets().get(0);
//Create a Cells object to fetch all the cells.
Cells cells = worksheet.getCells();
//Merge some Cells (C6:E7) into a single C6 Cell.
cells.merge(5,2,2,3);
//Input data into C6 Cell.
worksheet.getCells().get(5,2).setValue("This is a test of merging");
//Save the Workbook.
wbk.save(dataPath + "merge_Aspose_Out.xls");
// Print message
System.out.println("Process completed successfully");
}
示例4: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/hideunhidecells/data/";
Workbook workbook = new Workbook(dataPath + "workbook.xls");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
cells.hideRow(2); //Hiding the 3rd row of the worksheet
cells.hideColumn(1); //Hiding the 2nd column of the worksheet
//Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataPath + "hideUnhideCells_Aspose_Out.xls");
//Print message
System.out.println("Rows and Columns hidden successfully.");
}
示例5: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandling/findvalueincells/data/";
//Instantiating a Workbook object
Workbook workbook = new Workbook(dataPath + "workbook.xls");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
//Finding the cell containing the specified formula
Cells cells = worksheet.getCells();
//Instantiate FindOptions
FindOptions findOptions = new FindOptions();
//Finding the cell containing a string value that starts with "Or"
findOptions.setLookAtType(LookAtType.START_WITH);
Cell cell = cells.find("SH",null,findOptions);
//Printing the name of the cell found after searching worksheet
System.out.println("Name of the cell containing String: " + cell.getName());
}
示例6: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/datahandling/calculatesubtotals/data/";
//Instantiate a new workbook
Workbook workbook = new Workbook(dataPath + "book1.xls");
//Get the Cells collection in the first worksheet
Cells cells = workbook.getWorksheets().get(0).getCells();
//Create a cellarea i.e.., B3:C19
CellArea ca = new CellArea();
ca.StartRow = 2;
ca.StartColumn =1;
ca.EndRow = 18;
ca.EndColumn = 2;
//Apply subtotal, the consolidation function is Sum and it will applied to
//Second column (C) in the list
cells.subtotal(ca, 0, ConsolidationFunction.SUM, new int[] { 1 });
//Save the excel file
workbook.save(dataPath + "AsposeTotal_Out.xls");
// Print message
System.out.println("Process completed successfully");
}
示例7: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.add("My Worksheet");
Cells cells = worksheet.getCells();
//Adding some value to cell
Cell cell = cells.get("A1");
cell.setValue("This is Aspose test of fonts!");
//Saving the Excel file
workbook.save("data/xlsx4j/newWorksheet_Aspose.xls");
//Print Message
System.out.println("Sheet added successfully.");
}
示例8: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//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 8
worksheet.getCells().setStandardHeight(8f);
//Setting the height of the second row to 40
cells.setRowHeight(1, 40);
//Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(System.getProperty("user.dir") + "/data/xlsx4j/RowHeight-Aspose.xlsx");
//Print Message
System.out.println("Worksheet saved successfully.");
}
示例9: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Adding some sample value to cells
Cells cells = sheet.getCells();
Cell cell = cells.get("A1");
cell.setValue(50);
cell = cells.get("A2");
cell. setValue (100);
cell = cells.get("A3");
cell.setValue(150);
cell = cells.get("B1");
cell.setValue(4);
cell = cells.get("B2");
cell.setValue(20);
cell = cells.get("B3");
cell.setValue(50);
ChartCollection charts = sheet.getCharts();
// Adding a chart to the worksheet
int chartIndex = charts.add(ChartType.PYRAMID,5,0,15,5);
Chart chart = charts.get(chartIndex);
// Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
SeriesCollection serieses = chart.getNSeries();
serieses.add("A1:B3", true);
// Saving the Excel file
workbook.save("data/AsposeChart.xls");
// Print message
System.out.println("Workbook with chart is successfully created.");
}
示例10: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
//Instantiating a Workbook object
Workbook book = new Workbook();
//Obtaining the reference of the newly added worksheet
int sheetIndex = book.getWorksheets().add();
Worksheet worksheet = book.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
Cell cell = null;
//Adding a value to "A1" cell
cell = cells.get("A1");
cell.setValue(1);
//Adding a value to "A2" cell
cell = cells.get("A2");
cell.setValue(2);
//Adding a value to "A3" cell
cell = cells.get("A3");
cell.setValue(3);
//Adding a SUM formula to "A4" cell
cell = cells.get("A4");
cell.setFormula("=SUM(A1:A3)");
//Calculating the results of formulas
book.calculateFormula();
//Saving the Excel file
book.save("data/AsposeFormulaEngine.xls");
}
示例11: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet by passing its sheet index
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet= workbook.getWorksheets().get(sheetIndex);
//==================================================
//Creating an array containing names as string values
String[] names = new String[]{"laurence chen", "roman korchagin", "kyle huang"};
//Importing the array of names to 1st row and first column vertically
Cells cells = worksheet.getCells();
cells.importArray(names,0,0,false);
//==================================================
ArrayList<String> list = new ArrayList<String>();
//Add few names to the list as string values
list.add("laurence chen");
list.add("roman korchagin");
list.add("kyle huang");
//Importing the contents of ArrayList to 1st row and first column vertically
cells.importArrayList(list,2,0,true);
//==================================================
//Saving the Excel file
workbook.save("data/AsposeDataImport.xls");
}
示例12: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdata/gettingcellcontent/data/";
Workbook workbook = new Workbook(dataPath + "workbook.xls");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
//Access the Maximum Display Range
Range range = worksheet.getCells().getMaxDisplayRange();
int tcols = range.getColumnCount();
int trows = range.getRowCount();
System.out.println("Total Rows:" + trows);
System.out.println("Total Cols:" + tcols);
// Access value of Cell B4
//=====================================================
System.out.println(cells.get("B4").getValue());
Cell cell = cells.get(3,1); //Access value of Cell B4
System.out.println(cell.getValue());
//=====================================================
RowCollection rows = cells.getRows();
for (int i = 0 ; i < rows.getCount() ; i++)
{
for (int j = 0 ; j < tcols ; j++)
{
if (cells.get(i,j).getType() != CellValueType.IS_NULL)
{
System.out.println(cells.get(i,j).getName() + " - " + cells.get(i,j).getValue());
}
}
}
}
示例13: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdata/newlineincells/data/";
//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 with Explicit Line Breaks
cell.get(0, 0).setValue("I am using \nthe latest version of \nAspose.Cells \nto 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(dataPath + "Aspose-WrappingText.xls");
System.out.println("Done...");
}
示例14: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithworkbook/adddataincells/data/";
//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();
cells.get("A1").setValue("Hello World"); //Adding a string value to the cell
cells.get("A2").setValue(20.5); //Adding a double value to the cell
cells.get("A3").setValue(15); //Adding an integer value to the cell
cells.get("A4").setValue(true); //Adding a boolean value to the cell
Cell cell = cells.get("A5"); //Adding a date/time value to the cell
cell.setValue(java.util.Calendar.getInstance());
//Setting the display format of the date
Style style = cell.getStyle();
style.setNumber(15);
cell.setStyle(style);
workbook.save(dataPath + "DataInCells_Aspose_Out.xls"); //Saving the Excel file
// Print message
System.out.println("Data Added Successfully");
}
示例15: main
import com.aspose.cells.Cells; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithformattingfeatures/workingwithfonts/data/";
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
//Adding some value to cell
Cell cell = cells.get("A1");
cell.setValue("This is Aspose test of fonts!");
//Setting the font name to "Times New Roman"
Style style = cell.getStyle();
Font font = style.getFont();
font.setName("Courier New");
font.setSize(24);
font.setBold(true);
font.setUnderline(FontUnderlineType.SINGLE);
font.setColor(Color.getBlue());
font.setStrikeout(true);
//font.setSubscript(true);
cell.setStyle(style);
//Saving the modified Excel file in default format
workbook.save(dataPath + "AsposeFonts.xls");
System.out.println("Aspose Fonts Created.");
}