
How to Create Excel File With PivotTable and Chart Via VJ++
Hello Sir,
I have a problem, I am trying to create a new Excel file
via VJ++. And also I want to add PivoteTable and Chart
into that created Excle file. I am able to open a Excel
file but I am not able create a new Excel file. Can you
tell how I can create a Excel file with Pivote Table and
Pivote Chart using Visual J++ as well as please tell me
how i can provide Data Source to Pivote Table in VJ++ . I
am useing Sql Server 2000 Here is my code I am useing to
open a Excel file. Please help me on this matter Thanks.
Vijay Mundhe
//Code of Visual J++(VJ++) which i wrote
import com.ms.com.*;
import com.ms.wfc.io.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.app.*;
import java.sql .* ;
import java.io.* ;
public class PivotTable
{
private String UserName;
private String Password;
private Connection conn;
private Statement st1;
private ResultSet rs1;
private excel.Application app;
private excel.Workbook w1;
private excel.Worksheet ws;
private excel.PivotTable pt;
private String ds;
private Variant noParam = new Variant();
{
noParam.noParam();
}
public static void main (String[] args)
{
PivotTable pttb = new PivotTable();
pttb.creaeTable();
}
public void creaeTable()
{
System.out.println("In createTable method");
excel.Range range = null;
int lcid = cale.getUserDefaultLocale().getLCID();
app = new excel .Application ();
ws = new excel.Worksheet();
app.setVisible (lcid,true);
java.io.File f1;
String file;
try
{
String filename
="d:\\Vijay\\MicroDataWh\\PivotTable\\Aviall_Ageing_Fact.xl
s";
f1 = new java.io.File (filename);
if(f1.exists() )
{
System.out.println ("opening this
File :"+filename);
app.getWorkbooks ().Open(filename,noParam,new
Variant
(excel.XlFileAccess.xlReadWrite),noParam,noParam,noParam,no
Param,noParam,noParam,noParam,noParam,noParam,noParam,noPar
am,noParam,lcid);
w1 = app.getActiveWorkbook ();
System.in.read();
}
else
{
//Here if File is not found then I want to
//create a new Excel file and add Pivot table
//and add Dimension and Measures to that
//PivotTable.
System.out.println("File not found");
System.in.read();
}
}//try end
catch(Exception e)
{
System.out.println("Error : " + e.getMessage());
}//catch end
}//createTable method end
Quote:
}