XSSFSheet addMergedRegion + Region class moved to org.apache.poi.ss.util.Region + Region.getRegionRef method + tests

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645303 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Paolo Mottadelli 2008-04-06 20:34:00 +00:00
parent 4e01cda4ae
commit ba8c1c39a7
19 changed files with 92 additions and 18 deletions

View File

@ -24,7 +24,7 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
import org.apache.commons.lang.exception.NestableException;

View File

@ -20,7 +20,7 @@
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
import java.io.IOException;
import java.io.FileOutputStream;

View File

@ -23,6 +23,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.util.Region;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.*;

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record;
import org.apache.poi.hssf.record.cf.CellRange;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
import org.apache.poi.util.LittleEndian;
/**

View File

@ -24,7 +24,7 @@ import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;

View File

@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
/**
*

View File

@ -21,7 +21,7 @@ import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
import org.apache.poi.hssf.record.cf.CellRange;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
/**
* HSSFConditionalFormatting class encapsulates all settings of Conditional Formatting.

View File

@ -55,9 +55,9 @@ import org.apache.poi.hssf.record.formula.ReferencePtg;
import org.apache.poi.hssf.util.HSSFCellRangeAddress;
import org.apache.poi.hssf.util.HSSFDataValidation;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.Region;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;

View File

@ -16,7 +16,7 @@
==================================================================== */
package org.apache.poi.hssf.util;
package org.apache.poi.ss.util;
import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion;
@ -218,4 +218,14 @@ public class Region
return ((1 + (getRowTo() - getRowFrom()))
* (1 + (getColumnTo() - getColumnFrom())));
}
/**
* @return the string reference for this region
*/
public String getRegionRef() {
CellReference cellRefFrom = new CellReference(rowFrom, colFrom);
CellReference cellRefTo = new CellReference(rowTo, colTo);
String ref = cellRefFrom.formatAsString() + ":" + cellRefTo.formatAsString();
return ref;
}
}

View File

@ -20,7 +20,7 @@ package org.apache.poi.ss.usermodel;
import java.util.Iterator;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
public interface Sheet extends Iterable<Row> {

View File

@ -25,7 +25,6 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CommentsSource;
@ -37,6 +36,7 @@ import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.Region;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.apache.xmlbeans.XmlOptions;
@ -48,6 +48,8 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
@ -72,6 +74,7 @@ public class XSSFSheet implements Sheet {
protected ColumnHelper columnHelper;
protected XSSFWorkbook workbook;
protected CommentsSource sheetComments;
protected CTMergeCells ctMergeCells;
public static final short LeftMargin = 0;
public static final short RightMargin = 1;
@ -189,10 +192,18 @@ public class XSSFSheet implements Sheet {
}
public int addMergedRegion(Region region) {
// TODO Auto-generated method stub
return 0;
addNewMergeCell(region);
return ctMergeCells.sizeOfMergeCellArray();
}
private void addNewMergeCell(Region region) {
if (ctMergeCells == null) {
ctMergeCells = worksheet.addNewMergeCells();
}
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
ctMergeCell.setRef(region.getRegionRef());
}
public void autoSizeColumn(short column) {
columnHelper.setColBestFit(column, true);
}

View File

@ -20,7 +20,8 @@
package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
import org.apache.poi.util.TempFile;
import java.io.*;

View File

@ -20,7 +20,8 @@
package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
/**
* Test the ability to clone a sheet.

View File

@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hssf.util.*;
import org.apache.poi.ss.util.Region;
import java.io.*;
import java.util.*;

View File

@ -21,7 +21,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.util.Region;
/**
*
* @author Dmitriy Kumshayev

View File

@ -35,8 +35,8 @@ import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.VCenterRecord;
import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.util.Region;
import org.apache.poi.util.TempFile;
/**

View File

@ -25,8 +25,8 @@ import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.util.Region;
import org.apache.poi.util.TempFile;
import java.io.File;

View File

@ -15,7 +15,7 @@
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.util;
package org.apache.poi.ss.util;
import org.apache.poi.ss.util.CellReference;

View File

@ -0,0 +1,49 @@
/* ====================================================================
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 org.apache.poi.ss.util;
import junit.framework.TestCase;
/**
* Tests that the common CellReference works as we need it to
*/
public class TestRegion extends TestCase {
public void testGetRegionRef() {
int rowFrom = 3;
short colFrom = 3;
int rowTo = 9;
short colTo = 9;
Region region = new Region(rowFrom, colFrom, rowTo, colTo);
assertEquals("D4:J10", region.getRegionRef());
}
public void testContains() {
int rowFrom = 3;
short colFrom = 3;
int rowTo = 9;
short colTo = 9;
Region region = new Region(rowFrom, colFrom, rowTo, colTo);
assertEquals("D4:J10", region.getRegionRef());
assertTrue(region.contains(5, (short) 7));
assertTrue(region.contains(9, (short) 9));
assertFalse(region.contains(9, (short) 10));
}
}