import java.io.*;
import javax.swing.*;
import jxl.*; 
import jxl.write.*;
import jxl.format.*;
import java.io.File;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.swing.filechooser.*;
import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.text.*;
import java.util.Locale;
import java.sql.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
 
public class turkoglu_rehber_excel
{
   String isim[];
   double P[];
   String ciktidosyaismi;
   public static String toString(double left, int w, int d)
   // converts a double to a string with given width and decimals.
   {
    java.text.NumberFormat df=java.text.NumberFormat.getInstance(Locale.US);
    df.setMaximumFractionDigits(d);
    df.setMinimumFractionDigits(d);
    df.setGroupingUsed(false);
    String s = df.format(left);
    while (s.length() < w)
    s = " " + s;
    if (s.length() > w)
    {   s = "";
        for (int i=0; i<w; i++) s = s + "-";
    }
    return s;
    } 
    
     public static double[] verigir(String s)
     {
     String s1=JOptionPane.showInputDialog(s);        
     StringTokenizer token=new StringTokenizer(s1);
     int n=token.countTokens()-1;
     int m=n+1;
     double a[]=new double[m];
     int j=0;           
     while(token.hasMoreTokens())
     {
     Double ax=new Double(token.nextToken());
     a[j++]=ax.doubleValue();
     }
     return a; 
     }

public turkoglu_rehber_excel() throws IOException
{  String sr1[]={"alfabe","sira_no","channel_no","müsteri_tipi","firma_acik_unvani","fatura_adresi1","fatura_adresi2","fatura_adresi3","telefon_1","telefon_2","telefon_3","yetkili_kisi","telefon_GSM","email","web",
  "urun_sevk_adresi1","urun_sevk_adresi2","banka_hesap1","banka_hesap2","ek_not"};

  String dosyaismi="REHBER.xls";
  int snl=dosyaismi.length();   
  ciktidosyaismi="REHBER_C.xls";
  File f1=new File(ciktidosyaismi);
  File f=new File(dosyaismi);
  int n1=sr1.length; 
  int n2=19; 
  try
  {
  // excell girdi dosyası
  jxl.Workbook workbook = jxl.Workbook.getWorkbook(f); 
  // excell sayfa sayısı
  int nos=workbook.getNumberOfSheets();      
  jxl.write.WritableWorkbook workbook1 = jxl.Workbook.createWorkbook(f1);      
  jxl.write.WritableSheet wreportsheet = workbook1.createSheet("REHBER",0);    
  jxl.write.Label l1;
  jxl.write.Number number;
 try{
    jxl.write.WritableCellFormat wcf=new WritableCellFormat();
    wcf.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
    wcf.setWrap(true);    
    jxl.write.WritableCellFormat wcf1=new jxl.write.WritableCellFormat();
    wcf1.setBorder(jxl.format.Border.LEFT,jxl.format.BorderLineStyle.DOUBLE);
    wcf1.setWrap(true);    
    for(int ii=0;ii<sr1.length;ii++)
    {
    l1=new jxl.write.Label(ii,0,sr1[ii]);
    l1.setCellFormat(wcf);    
    wreportsheet.addCell(l1);
    }
String stringa1="aaa";
String str2="aaa"; 
int i=0;
 jxl.write.Label a1;
 Sheet sheet;
 sheet = workbook.getSheet(2);
 Cell a2 = sheet.getCell(6,1);
  int j,k=0,k1=0;
  System.out.println("0,0="+a2.getContents());
  try
  {  
  while(stringa1!="")
  {
  k1=i*n2+1;  
  for(j=0;j<n2;j++)	   
  {k=k1+j;a2 = sheet.getCell(6,k);
  if(j==0) stringa1 = a2.getContents();
  }
  System.out.println(stringa1+"k="+k);
    i++;	  
  }
  }catch(ArrayIndexOutOfBoundsException ai) {}  
  //bu excell sayfası için satır sayısı = n 
  int n=i-1;
  String a[][]=new String[n2][n];
  System.out.println("VERİ SAYISI="+n);
  for(i=0;i<n;i++)
  {
  k1=i*n2+1;
  for(int ii=0;ii<4;ii++)
  {a2=sheet.getCell(ii,k1);
  str2=a2.getContents();
  //System.out.println("j="+j+"ii="+ii+"str2="+str2);
  jxl.write.Label l2=new jxl.write.Label(ii,i+1,str2);
  l2.setCellFormat(wcf);
  wreportsheet.addCell(l2);
  } //for ii 
     
  for(j=0;j<n2;j++)
  {k=k1+j;
  jxl.write.Label l2;
  
  
  a2= sheet.getCell(6,k);a[j][i]=a2.getContents();
  l2=new jxl.write.Label(j+4,i+1,a[j][i]);
  l2.setCellFormat(wcf);
  wreportsheet.addCell(l2);

  } //for j 
  } //for i
workbook1.write();
workbook1.close(); 
}catch(jxl.write.WriteException we) {System.out.println("write exception");}
}catch(jxl.read.biff.BiffException be) {System.err.println("BiffException");}  


}

public static void main(String arg[])
{turkoglu_rehber_excel x;
      try{x=new turkoglu_rehber_excel();    
         } catch(IOException ee) 
    {System.out.println("Okuma hatası lütfen excell girdi dosyasının kapalı olduğuna emin olun");}
}
}