package com.foc.vaadin.gui.tableExports;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;

import com.foc.Globals;
import com.foc.util.Utils;

public class EXCELSheet implements Cloneable {
	private String name = null;
	private XSSFSheet sheet = null;
	private int rowCount = 0;
	private int columnCount = 0;
	private XSSFRow row = null;
	private XSSFCell cell = null;

	public EXCELSheet(String name, XSSFSheet sheet) {
		this.sheet = sheet;
		this.name = name;
		rowCount = 0;
		columnCount = 0;
		row = null;
		cell = null;
	}

	public void dispose() {
		sheet = null;
		row = null;
		cell = null;
	}
	
	@Override
	protected EXCELSheet clone() throws CloneNotSupportedException {
		return (EXCELSheet) super.clone();
	}
	
	public void addNewLine() {
		try{
			if(this.sheet != null){
				this.row = this.sheet.createRow(this.rowCount++);
				this.columnCount = 0;
			}
		}catch (Exception localException){
			localException.printStackTrace();
		}
	}
	
	public void setRightToLeft(boolean r2l) {
		if(this.sheet != null){
			this.sheet.setRightToLeft(r2l);
		}
	}
	
	public void addCellValue(Object paramObject, int paramInt) {
		String str = "";
		try{
			while (paramInt > 0){
				str = str + " ";
				paramInt--;
			}
			addCellValue("\"" + str + paramObject + "\"");
		}catch (Exception localException){
			Globals.logException(localException);
		}
	}

	public void addCellValue(Object paramObject) {
		try{
			XSSFCell localXSSFCell = this.row.createCell(this.columnCount++);
			if((paramObject instanceof String)){
				if(Utils.isNumeric((String) paramObject)){
					double d = Double.parseDouble((String) paramObject);
					localXSSFCell.setCellValue(d);
				}else{
					localXSSFCell.setCellValue((String) paramObject);
				}
			}
		}catch (Exception localException){
			Globals.logException(localException);
		}
	}

}
@@ -1576,53 +1576,28 @@
 %0A%09%09%09
-XSSFCell localXSSFCell = this.row.createCell(
+int currentColumn = 
 this
@@ -1606,25 +1606,24 @@
 olumnCount++
-)
 ;%0D%0A%09%09%09if((pa
@@ -1662,27 +1662,23 @@
 %09%09%09%09
-if(Utils.isNumeric(
+String value = 
 (Str
@@ -1693,21 +1693,166 @@
 amObject
+;%0D%0A%09%09%09%09if(value != null && !value.isEmpty(
 ))
+ 
 %7B%0D%0A
+%09%09%09%09%09XSSFCell localXSSFCell = this.row.createCell(currentColumn);%0D%0A%09%09%09%09%09if(Utils.isNumeric(value))%7B%0D%0A%09
 %09%09%09%09%09dou
@@ -1882,32 +1882,18 @@
 ble(
-(String) paramObject
+value
 );%0D%0A
+%09
 %09%09%09%09
@@ -1933,16 +1933,17 @@
 %09%09%09%09
+%09
 %7Delse%7B%0D%0A
 %09%09%09%09
@@ -1938,16 +1938,17 @@
 %7Delse%7B%0D%0A
+%09
 %09%09%09%09%09loc
@@ -1975,30 +1975,23 @@
 lue(
-(String) paramObject);
+value);%0D%0A%09%09%09%09%09%7D
 %0D%0A%09%09

Enhance Excel sheet filling performance by not calling row.createCell when the string sent is empty