Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package featurescomparison.workingwithcellsrowscolumns.addcomments.java;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class ApacheAddCommentsToCell
{
public static void main(String[] args) throws IOException
{
String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/addcomments/data/";

Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();

CreationHelper factory = wb.getCreationHelper();

Sheet sheet = wb.createSheet();

Row row = sheet.createRow(3);
Cell cell = row.createCell(5);
cell.setCellValue("F4");

Drawing drawing = sheet.createDrawingPatriarch();

// When the comment box is visible, have it show in a 1x3 space
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex()+1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum()+3);

// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString("Hello, World!");
comment.setString(str);
comment.setAuthor("Apache POI");

// Assign the comment to the cell
cell.setCellComment(comment);

String fname = "AsposeComment-xssf.xls";
if(wb instanceof XSSFWorkbook) fname += "x";
FileOutputStream out = new FileOutputStream(dataPath + fname);
wb.write(out);
out.close();
System.out.println("Done.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package featurescomparison.workingwithcellsrowscolumns.addcomments.java;

import com.aspose.cells.Comment;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class AsposeAddCommentsToCell
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/addcomments/data/";

//Instantiating a Workbook object
Workbook workbook = new Workbook();

Worksheet worksheet = workbook.getWorksheets().get(0);

//Adding a comment to "F5" cell
int commentIndex = worksheet.getComments().add("F5");
Comment comment = worksheet.getComments().get(commentIndex);

//Setting the comment note
comment.setNote("Hello Aspose!");

//Saving the Excel file
workbook.save(dataPath + "AsposeComments.xls");

System.out.println("Done.");
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

package featurescomparison.workingwithcellsrowscolumns.splitpanes.java;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;

/**
* How to set split panes
*/
public class ApacheSplitPanes
{
public static void main(String[]args) throws Exception
{

String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/splitpanes/data/";

Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");

// Create a split with the lower left side being the active quadrant
sheet.createSplitPane(2000, 2000, 0, 0, Sheet.PANE_LOWER_LEFT);

FileOutputStream fileOut = new FileOutputStream(dataPath + "ApacheSplitFreezePanes.xlsx");
wb.write(fileOut);
fileOut.close();
System.out.println("Done.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package featurescomparison.workingwithcellsrowscolumns.splitpanes.java;

import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;

public class AsposeSplitPanes
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/splitpanes/data/";

//Instantiate a new workbook / Open a template file
Workbook book = new Workbook(dataPath + "workbook.xls");

//Set the active cell
book.getWorksheets().get(0).setActiveCell("A20");

//Split the worksheet window
book.getWorksheets().get(0).split();

//Save the Excel file
book.save(dataPath + "AsposeSplitPanes.xls", SaveFormat.EXCEL_97_TO_2003);

System.out.println("Done.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package featurescomparison.workingwithformattingfeatures.cellalignment.java;

import org.apache.poi.hssf.usermodel.*;

import java.io.FileOutputStream;
import java.io.IOException;

/**
* Shows how various alignment options work.
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class ApacheCellAlignment
{
public static void main(String[] args) throws IOException
{
String dataPath = "src/featurescomparison/workingwithformattingfeatures/cellalignment/data/";

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(2);
createCell(wb, row, 0, HSSFCellStyle.ALIGN_CENTER);
createCell(wb, row, 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
createCell(wb, row, 2, HSSFCellStyle.ALIGN_FILL);
createCell(wb, row, 3, HSSFCellStyle.ALIGN_GENERAL);
createCell(wb, row, 4, HSSFCellStyle.ALIGN_JUSTIFY);
createCell(wb, row, 5, HSSFCellStyle.ALIGN_LEFT);
createCell(wb, row, 6, HSSFCellStyle.ALIGN_RIGHT);

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(dataPath + "ApahceAlignment.xls");
wb.write(fileOut);
fileOut.close();
System.out.println("Done.");
}

/**
* Creates a cell and aligns it a certain way.
*
* @param wb the workbook
* @param row the row to create the cell in
* @param column the column number to create the cell in
* @param align the alignment for the cell.
*/
private static void createCell(HSSFWorkbook wb, HSSFRow row, int column, int align) {
HSSFCell cell = row.createCell(column);
cell.setCellValue("Align It");
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment((short)align);
cell.setCellStyle(cellStyle);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package featurescomparison.workingwithformattingfeatures.cellalignment.java;

import com.aspose.cells.Cell;
import com.aspose.cells.Cells;
import com.aspose.cells.Style;
import com.aspose.cells.TextAlignmentType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class AsposeCellAlignment
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithformattingfeatures/cellalignment/data/";

//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(dataPath + "AsposeCellsAlignment.xls");

System.out.println("Done.");
}
}
Binary file not shown.
Loading