Java Code Examples for org.apache.poi.hssf.usermodel.HSSFWorkbook#getSheetName()

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFWorkbook#getSheetName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportToExcelManager.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private int countSheetFromTemplate(final HSSFWorkbook workbook, final ERDiagram diagram) {
    int count = 0;

    for (int sheetNo = 0; sheetNo < workbook.getNumberOfSheets(); sheetNo++) {
        final String templateSheetName = workbook.getSheetName(sheetNo);

        final AbstractSheetGenerator sheetGenerator = getSheetGenerator(templateSheetName);

        if (sheetGenerator != null) {
            count += sheetGenerator.count(diagram);

        } else {
            count++;
        }
    }

    if (exportExcelSetting.isPutERDiagramOnExcel()) {
        count += 1;
    }

    return count;
}
 
Example 2
Source File: TriggerSheetGenerator.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {

    for (final Trigger trigger : diagram.getDiagramContents().getTriggerSet()) {
        final String name = trigger.getName();
        final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, name, sheetNameMap);

        final String sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));
        monitor.subTaskWithCounter("[Trigger] " + sheetName);

        sheetObjectMap.put(sheetName, trigger);

        setTriggerData(workbook, newSheet, trigger);
        monitor.worked(1);
    }
}
 
Example 3
Source File: SequenceSheetGenerator.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {

    for (final Sequence sequence : diagram.getDiagramContents().getSequenceSet()) {
        final String name = sequence.getName();

        final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, name, sheetNameMap);

        final String sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));
        monitor.subTaskWithCounter("[Sequence] " + sheetName);

        sheetObjectMap.put(sheetName, sequence);

        setSequenceData(workbook, newSheet, sequence, diagram);
        monitor.worked(1);
    }
}
 
Example 4
Source File: IndexSheetGenerator.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {
    clear();

    for (final ERTable table : diagram.getDiagramContents().getContents().getTableSet()) {
        if (diagram.getCurrentCategory() != null && !diagram.getCurrentCategory().contains(table)) {
            continue;
        }

        for (final Index index : table.getIndexes()) {
            final String name = index.getName();

            final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, name, sheetNameMap);

            final String sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));
            monitor.subTaskWithCounter("[Index] " + sheetName);

            sheetObjectMap.put(sheetName, index);

            setIndexData(workbook, newSheet, index);
            monitor.worked(1);
        }
    }
}
 
Example 5
Source File: ExportToExcelManager.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private int countSheetFromTemplate(HSSFWorkbook workbook, ERDiagram diagram) {
	int count = 0;

	for (int sheetNo = 0; sheetNo < workbook.getNumberOfSheets(); sheetNo++) {
		String templateSheetName = workbook.getSheetName(sheetNo);

		AbstractSheetGenerator sheetGenerator = this
				.getSheetGenerator(templateSheetName);

		if (sheetGenerator != null) {
			count += sheetGenerator.count(diagram);

		} else {
			count++;
		}
	}

	return count;
}
 
Example 6
Source File: TableSheetGenerator.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {
    clear();

    List<ERTable> nodeSet = null;

    if (diagram.getCurrentCategory() != null) {
        nodeSet = diagram.getCurrentCategory().getTableContents();
    } else {
        nodeSet = diagram.getDiagramContents().getContents().getTableSet().getList();
    }

    for (final ERTable table : nodeSet) {
        String name = null;
        if (useLogicalNameAsSheetName) {
            name = table.getLogicalName();
        } else {
            name = table.getPhysicalName();
        }

        final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, name, sheetNameMap);

        final String sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));
        monitor.subTaskWithCounter("[Table] " + sheetName);

        sheetObjectMap.put(sheetName, table);

        setTableData(workbook, newSheet, table);

        monitor.worked(1);
    }
}
 
Example 7
Source File: ViewSheetGenerator.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {
    clear();

    List<View> nodeSet = null;

    if (diagram.getCurrentCategory() != null) {
        nodeSet = diagram.getCurrentCategory().getViewContents();
    } else {
        nodeSet = diagram.getDiagramContents().getContents().getViewSet().getList();
    }

    for (final View view : nodeSet) {
        String name = null;
        if (useLogicalNameAsSheetName) {
            name = view.getLogicalName();
        } else {
            name = view.getPhysicalName();
        }

        final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, name, sheetNameMap);

        final String sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));
        monitor.subTaskWithCounter("[View] " + sheetName);

        sheetObjectMap.put(sheetName, view);

        setViewData(workbook, newSheet, view);

        monitor.worked(1);
    }
}
 
Example 8
Source File: ColumnSheetGenerator.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {
    final String name = getSheetName();
    final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, name, sheetNameMap);

    final String sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));

    sheetObjectMap.put(sheetName, new ColumnSet());

    setAllColumnsData(monitor, workbook, newSheet, diagram);
}
 
Example 9
Source File: XlsDataSet.java    From Leo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new XlsDataSet object that loads the specified Excel document.
 */
public XlsDataSet(InputStream in) throws IOException, DataSetException {
    _tables = super.createTableNameMap();

    HSSFWorkbook workbook = new HSSFWorkbook(in);
    int sheetCount = workbook.getNumberOfSheets();
    for (int i = 0; i < sheetCount; i++) {
        ITable table = new XlsTable(workbook, workbook.getSheetName(i),
                workbook.getSheetAt(i));
        _tables.add(table.getTableMetaData().getTableName(), table);
    }
}
 
Example 10
Source File: XlsDataSet.java    From Leo with Apache License 2.0 5 votes vote down vote up
/**
 * 从Excel的工作簿中创建XlsDataSet.
 */
@Deprecated
public XlsDataSet(HSSFWorkbook workbook) throws IOException, DataSetException {
    _tables = super.createTableNameMap();

    int sheetCount = workbook.getNumberOfSheets();
    for (int i = 0; i < sheetCount; i++) {
        ITable table = new XlsTable(workbook, workbook.getSheetName(i),
                workbook.getSheetAt(i));
        _tables.add(table.getTableMetaData().getTableName(), table);
    }
}
 
Example 11
Source File: ExportToExcelManager.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
private void initSheetNameMap(final HSSFWorkbook workbook) {
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        final String sheetName = workbook.getSheetName(i);
        sheetNameMap.put(sheetName.toUpperCase(), 0);
    }
}
 
Example 12
Source File: ExportToExcelManager.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
private void createSheetFromTemplate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final ERDiagram diagram, final boolean useLogicalNameAsSheetName) throws InterruptedException {
    initSheetNameMap(workbook);

    int originalSheetNum = workbook.getNumberOfSheets();

    int sheetIndexSheetNo = -1;

    while (originalSheetNum > 0) {
        final String templateSheetName = workbook.getSheetName(0);

        final AbstractSheetGenerator sheetGenerator = getSheetGenerator(templateSheetName);

        if (sheetGenerator != null) {
            sheetGenerator.generate(monitor, workbook, 0, useLogicalNameAsSheetName, sheetNameMap, sheetObjectMap, diagram, loopDefinitionMap);
            workbook.removeSheetAt(0);

        } else {
            if (!isExcludeTarget(templateSheetName)) {
                moveSheet(workbook, 0);
                final HSSFSheet sheet = workbook.getSheetAt(workbook.getNumberOfSheets() - 1);

                sheetObjectMap.put(templateSheetName, new StringObjectModel(templateSheetName));

                if (pictureSheetGenerator != null) {
                    pictureSheetGenerator.setImage(workbook, sheet);
                }

                if (sheetIndexSheetGenerator.getTemplateSheetName().equals(templateSheetName)) {
                    sheetIndexSheetNo = workbook.getNumberOfSheets() - originalSheetNum;

                    String name = sheetIndexSheetGenerator.getSheetName();

                    name = AbstractSheetGenerator.decideSheetName(name, sheetNameMap);

                    monitor.subTaskWithCounter(name);

                    workbook.setSheetName(workbook.getNumberOfSheets() - 1, name);
                } else {
                    monitor.subTaskWithCounter(sheet.getSheetName());
                }

            } else {
                monitor.subTaskWithCounter("Removing template sheet");
                workbook.removeSheetAt(0);
            }

            monitor.worked(1);
        }

        originalSheetNum--;
    }

    if (sheetIndexSheetNo != -1) {
        sheetIndexSheetGenerator.generate(monitor, workbook, sheetIndexSheetNo, useLogicalNameAsSheetName, sheetNameMap, sheetObjectMap, diagram, loopDefinitionMap);
    }
}
 
Example 13
Source File: HistorySheetGenerator.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void generate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final int sheetNo, final boolean useLogicalNameAsSheetName, final Map<String, Integer> sheetNameMap, final Map<String, ObjectModel> sheetObjectMap, final ERDiagram diagram, final Map<String, LoopDefinition> loopDefinitionMap) throws InterruptedException {

    String sheetName = getSheetName();

    final HSSFSheet newSheet = createNewSheet(workbook, sheetNo, sheetName, sheetNameMap);

    sheetName = workbook.getSheetName(workbook.getSheetIndex(newSheet));
    monitor.subTaskWithCounter(sheetName);

    sheetObjectMap.put(sheetName, new StringObjectModel(sheetName));

    setHistoryListData(workbook, newSheet, sheetObjectMap, diagram);
    monitor.worked(1);
}
 
Example 14
Source File: ExportToExcelManager.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
private void createSheetFromTemplate(IProgressMonitor monitor,
		HSSFWorkbook workbook, ERDiagram diagram,
		boolean useLogicalNameAsSheetName) throws InterruptedException {
	int originalSheetNum = workbook.getNumberOfSheets();

	int sheetIndexSheetNo = -1;

	while (originalSheetNum > 0) {
		String templateSheetName = workbook.getSheetName(0);

		AbstractSheetGenerator sheetGenerator = this
				.getSheetGenerator(templateSheetName);

		if (sheetGenerator != null) {
			sheetGenerator.generate(monitor, workbook, 0,
					useLogicalNameAsSheetName, this.sheetNameMap,
					this.sheetObjectMap, diagram, loopDefinitionMap);
			workbook.removeSheetAt(0);

		} else {
			System.out.println("non sheet generator :  " + templateSheetName);
			if (!isExcludeTarget(templateSheetName)) {
				moveSheet(workbook, 0);
				HSSFSheet sheet = workbook.getSheetAt(workbook.getNumberOfSheets() - 1);

				this.sheetObjectMap.put(templateSheetName,
						new StringObjectModel(templateSheetName));

				this.pictureSheetGenerator.setImage(workbook, sheet);

				if (this.sheetIndexSheetGenerator.getTemplateSheetName()
						.equals(templateSheetName)) {
					sheetIndexSheetNo = workbook.getNumberOfSheets()
							- originalSheetNum;

					String name = this.sheetIndexSheetGenerator
							.getSheetName();

					workbook.setSheetName(workbook.getNumberOfSheets() - 1,
							AbstractSheetGenerator.decideSheetName(name,
									sheetNameMap));
				}

			} else {
				workbook.removeSheetAt(0);
			}

			monitor.worked(1);
		}

		originalSheetNum--;

		if (monitor.isCanceled()) {
			throw new InterruptedException("Cancel has been requested.");
		}
	}

	if (sheetIndexSheetNo != -1) {
		this.sheetIndexSheetGenerator.generate(monitor, workbook,
				sheetIndexSheetNo, useLogicalNameAsSheetName,
				this.sheetNameMap, this.sheetObjectMap, diagram,
				loopDefinitionMap);
	}
}