All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jasperreports.engine.export.ooxml.DocxTableHelper Maven / Gradle / Ivy

There is a newer version: 6.21.3
Show newest version
/*
 * JasperReports - Free Java Reporting Library.
 * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of JasperReports.
 *
 * JasperReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JasperReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JasperReports. If not, see .
 */
package net.sf.jasperreports.engine.export.ooxml;

import java.io.Writer;

import net.sf.jasperreports.engine.JRPrintElementIndex;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.PrintPageFormat;
import net.sf.jasperreports.engine.export.CutsInfo;
import net.sf.jasperreports.engine.export.JRExporterGridCell;
import net.sf.jasperreports.engine.export.LengthUtil;


/**
 * @author Teodor Danciu ([email protected])
 */
public class DocxTableHelper extends BaseHelper
{
	/**
	 * 
	 */
	private CutsInfo xCuts;
	private DocxCellHelper cellHelper;
	private DocxParagraphHelper paragraphHelper;
	private PrintPageFormat pageFormat;
	private JRPrintElementIndex frameIndex;
	private int rowMaxTopPadding;

	/**
	 * 
	 */
	protected DocxTableHelper(
		JasperReportsContext jasperReportsContext,
		Writer writer,
		CutsInfo xCuts,
		boolean pageBreak,
		PrintPageFormat pageFormat,
		JRPrintElementIndex frameIndex
		) 
	{
		super(jasperReportsContext, writer);

		this.xCuts = xCuts;
		this.cellHelper = new DocxCellHelper(jasperReportsContext, writer);
		this.paragraphHelper = new DocxParagraphHelper(jasperReportsContext, writer, pageBreak);
		this.pageFormat = pageFormat;
		this.frameIndex = frameIndex;
	}


	/**
	 * 
	 */
	public DocxCellHelper getCellHelper() 
	{
		return cellHelper;
	}
	

	/**
	 * 
	 */
	public DocxParagraphHelper getParagraphHelper() 
	{
		return paragraphHelper;
	}
	

	/**
	 * 
	 */
	public void exportHeader() 
	{
		write("  \n");
		write("   \n");
		write("    \n");
		write("   \n");
		write("   \n");
		int leftColumnWidth = xCuts.getCutOffset(1) - xCuts.getCutOffset(0);
		if(frameIndex == null)
		{
			leftColumnWidth -= Math.min(leftColumnWidth, pageFormat.getLeftMargin());
			write("    \n");
		}
		else
		{
			write("    \n");
		}
		for(int col = 2; col < xCuts.size() - 1; col++)
		{
			write("    \n");
		}
		if(xCuts.size() > 1)
		{
			int rightColumnWidth = xCuts.getCutOffset(xCuts.size() - 1) - xCuts.getCutOffset(xCuts.size() - 2);
			if(frameIndex == null)
			{
				rightColumnWidth -= Math.min(rightColumnWidth, pageFormat.getRightMargin());
				write("    \n");
			}
			else
			{
				write("    \n");
			}
		}
		write("   \n");
	}
	
	public void exportFooter() 
	{
		write("  \n");
	}
	
	public void exportRowHeader(int rowHeight, boolean allowRowResize) 
	{
		write("   \n");
		write("    \n");
		write("     \n");
		write("    \n");
	}
	
	public void exportRowFooter() 
	{
		write("   \n");
	}
	
	public void exportEmptyCell(JRExporterGridCell gridCell, int emptyCellColSpan)
	{
		exportEmptyCell(gridCell, emptyCellColSpan, false, 0l, null);
	}
	
	public void exportEmptyCell(JRExporterGridCell gridCell, int emptyCellColSpan, boolean startPage, long bookmarkIndex, String pageAnchor)
	{
		write("    \n");
		write("     \n");
		if (emptyCellColSpan > 1)
		{
			write("      \n");
		}
		
		if (gridCell != null)
		{
			cellHelper.exportProps(gridCell);
		}
		
		write("     \n");
		
		paragraphHelper.exportEmptyParagraph(startPage, bookmarkIndex, pageAnchor);

		write("    \n");
	}

	public void exportOccupiedCells(JRExporterGridCell gridCell)
	{
		exportOccupiedCells(gridCell, false, 0l, null);
	}
	
	public void exportOccupiedCells(JRExporterGridCell gridCell, boolean startPage, long bookmarkIndex, String pageAnchor)
	{
		write("    \n");
		write("     \n");
		if (gridCell.getColSpan() > 1)
		{
			write("      \n");
		}
		write("      \n");
		
		cellHelper.exportProps(gridCell.getElement(), gridCell);
		
		write("     \n");
		
		paragraphHelper.exportEmptyParagraph(startPage, bookmarkIndex, pageAnchor);

		cellHelper.exportFooter();
	}
	
	public int getRowMaxTopPadding()
	{
		return rowMaxTopPadding;
	}
	
	public void setRowMaxTopPadding(int rowMaxTopPadding)
	{
		this.rowMaxTopPadding = rowMaxTopPadding;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy