Hi All,
Sorry for the delay.we have changed our code a little bit but again we are getting the same exception as we mentioned earlier.here we are attaching the latest code with the required files.
please check this and get back to us as early as possible.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import com.aspose.cells.Cells;
import com.aspose.cells.FileFormatType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class Five{
Workbook finalworkbook = new Workbook();
Worksheet worksheet2 = finalworkbook.getWorksheets().getSheet(0);
static int index=1;
public void combineReport(String filename,String filename2,String filename3) throws Exception {
double d1=0;
double f1=0;
System.out.println("In combinereport()");
Five d=new Five();
Workbook cbworkbook = new Workbook();
System.out.println("Before opening the cb workbook()");
cbworkbook.open(filename);
Worksheet sheet = cbworkbook.getWorksheets().getSheet(0);
HashSet hs2=adwordsProgram(filename2);
Iterator ik= hs2.iterator();
while(ik.hasNext())
{
String f=(String)ik.next();
System.out.print("\nrama "+f);
String f2=f.substring(0,f.indexOf("@"));
String f3=f.substring(f.indexOf("@")+1,f.indexOf("$"));
String f4=f.substring(f.indexOf("$")+1,f.indexOf("#"));
String f5=f.substring(f.indexOf("#")+1,f.length());
System.out.println("\nf2 is "+f2);
System.out.println("\nf3 is "+f3);
System.out.println("\nf4 is "+f4);
System.out.println("\nf5 is "+f5);
combineReport1(f2,f3,f4,f5,filename,filename2,filename3);
// s.nosalesGrouping(f1,f2,adwords_filename,nosales_filename);
}
}
public void combineReport1(String tid1,String pub1,String Adg,String camp,String filename,String filename2,String filename3)throws Exception
{
double d=0;
double f=0;
Connection c = null;
Statement stmnt = null;
System.out.println("In combinereport1");
worksheet2.getCells().getCell(0,0).setValue("TrackId");
worksheet2.getCells().getCell(0,1).setValue("AdGroup");
worksheet2.getCells().getCell(0,2).setValue("Publisher");
worksheet2.getCells().getCell(0,3).setValue("Cost");
worksheet2.getCells().getCell(0,4).setValue("Amount");
worksheet2.getCells().getCell(0,5).setValue("Campaign");
worksheet2.getCells().getCell(0,6).setValue("P/L");
worksheet2.getCells().getCell(0,7).setValue("P/L%");
Cells worksheet2_cells=worksheet2.getCells();
worksheet2_cells.setColumnWidth(0,10);
worksheet2_cells.setColumnWidth(1,35);
worksheet2_cells.setColumnWidth(2,35);
worksheet2_cells.setColumnWidth(3,8);
worksheet2_cells.setColumnWidth(4,35);
worksheet2_cells.setColumnWidth(5,45);
worksheet2_cells.setColumnWidth(6,10);
worksheet2_cells.setColumnWidth(7,10);
Class.forName("com.hxtt.sql.excel.ExcelDriver").newInstance();
System.out.println(" Before url");
String url="jdbc:excel:////"+filename2+" ";
System.out.println(" After url");
System.out.println("Before Connection");
c = DriverManager.getConnection(url, "", "");
System.out.println("After Connection");
stmnt = c.createStatement();
stmnt.setFetchSize(1000);
String s=null;
System.out.println("Before query");
String query = " Select * from Sheet1 where TrackId = '"+tid1+"' and Publisher = '"+pub1+"' and AdGroup = '"+Adg+"' and Campaign='"+camp+"' ;" ;
System.out.println("After query");
ResultSet rs = stmnt.executeQuery( query );
System.out.println("After Exceuting the query");
while(rs.next())
{
d=rs.getDouble("Cost");
System.out.println("the value of d is"+d);
f=d+f;
worksheet2.getCells().getCell(index,0).setValue(tid1);
worksheet2.getCells().getCell(index,1).setValue(Adg);
worksheet2.getCells().getCell(index,2).setValue(pub1);
worksheet2.getCells().getCell(index,3).setValue(d);
worksheet2.getCells().getCell(index,5).setValue(camp);
index++;
}
Cells p=worksheet2.getCells();
int m1=p.getMaxRow();
System.out.println("m1 is "+m1);
int m2=m1+1;
worksheet2.getCells().getCell(m2,0).setValue(" ");
worksheet2.getCells().getCell(m2,1).setValue(" ");
worksheet2.getCells().getCell(m2,2).setValue(" ");
worksheet2.getCells().getCell(m2,3).setValue(f);
int m3=p.getMaxRow();
System.out.println("m3 is "+m3);
int m4=m3+1;
worksheet2.getCells().getCell(m4,0).setValue(" ");
worksheet2.getCells().getCell(m4,1).setValue(" ");
worksheet2.getCells().getCell(m4,2).setValue(" ");
worksheet2.getCells().getCell(m4,3).setValue(" ");
worksheet2.getCells().getCell(m4,4).setValue(" ");
worksheet2.getCells().getCell(m4,5).setValue("");
System.out.println("m4 is index is "+m4);
int m5=m4+1;
index=m5;
try{
finalworkbook.save(filename3,FileFormatType.DEFAULT);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public HashSet adwordsProgram(String filename4)throws Exception
{
HashSet hs1=new HashSet();
int i=0;
Workbook adwordsworkbook = new Workbook();
System.out.println("Before opening the second work book");
System.out.println("filename2 is "+filename4);
adwordsworkbook.open(filename4);
Worksheet worksheet = adwordsworkbook.getWorksheets().getSheet(0);
System.out.println("that is adwords file");
Connection c = null;
Statement stmnt = null;
try
{
Class.forName("com.hxtt.sql.excel.ExcelDriver").newInstance();
System.out.println(" Before url");
String url="jdbc:excel:////"+filename4+" ";
System.out.println(" After url");
System.out.println("Before Connection");
c = DriverManager.getConnection(url, "", "");
System.out.println("After Connection");
stmnt = c.createStatement();
stmnt.setFetchSize(1000);
String s=null;
System.out.println("Before query");
String query = " Select * from Sheet1" ;
System.out.println("After query");
ResultSet rs = stmnt.executeQuery( query );
System.out.println("After Exceuting the query");
while(rs.next())
{
String tid=rs.getString("TrackId");
String pub=rs.getString("Publisher");
String Adgroup=rs.getString("AdGroup");
String camp=rs.getString("Campaign");
//System.out.println("RAMA Trackid is "+tid);
//System.out.println("RAMA publisher is "+pub);
//System.out.println("RAMA Adgroup is "+Adgroup);
//System.out.println("RAMA campaign is "+camp);
String finalString=tid+"@"+pub+"$"+Adgroup+"#"+camp;
//System.out.println("srikanth finalString is "+finalString);
hs1.add(finalString);
i++;
}
System.out.println("i is "+i);
int n=hs1.size();
System.out.println("Hash set size is "+n);
}
catch(Exception e)
{
System.out.println("Exception due to "+e);
}
return hs1;
}
public static void main(String[] args)throws Exception {
String f="e:/report2.xls";
String j="e:/CB1.xls";
String s="e:/report3.xls";
Five u=new Five();
u.combineReport(j,f,s);
}
}