excelden veri okuma

130 views
Skip to first unread message

Nazli Purde Savul

unread,
Nov 6, 2013, 8:10:17 AM11/6/13
to altdotne...@googlegroups.com

Merhaba,

Netbeansda proje geliştiriyorum. Mevcut excel verisini okuyup,  bir integer array içerisinde tutması gerekiyor nasıl yapabilirim? 

Nazli Purde Savul

unread,
Nov 6, 2013, 8:15:49 AM11/6/13
to altdotne...@googlegroups.com
package javaexcelread;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class NewExcel 
{

    private String inputFile;

    public void setInputFile(String inputFile) 
    {
        this.inputFile = inputFile;
    }

    public void read() throws IOException  
    {
        File inputWorkbook = new File(inputFile);
        Workbook w;
        try 
        {
            w = Workbook.getWorkbook(inputWorkbook);
            // Get the first sheet
            Sheet sheet = w.getSheet(0);
            // Loop over first 10 column and lines

            for (int j = 0; j < sheet.getColumns(); j++) 
            {
                for (int i = 0; i < sheet.getRows(); i++) 
                {
                    Cell cell = sheet.getCell(j, i);
                    System.out.print(cell.getContents());
                }
                System.out.println();
            }
        } 
        catch (BiffException e) 
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException 
    {
        NewExcel test = new NewExcel();
        test.setInputFile("C:\\Users\\Administrator\\Desktop\\TEZZZZ\\excelverileri\\ZEMIN.xls");
        test.read();
    }

}

veriyi okuyor ancak nasıl bir array içersinde tutarım onu bulamadım


6 Kasım 2013 15:10 tarihinde Nazli Purde Savul <nazli...@gmail.com> yazdı:


Merhaba,

Netbeansda proje geliştiriyorum. Mevcut excel verisini okuyup,  bir integer array içerisinde tutması gerekiyor nasıl yapabilirim? 



--
Nazlı PURDE SAVUL
İTÜ-MTBT

Arda Çetinkaya

unread,
Nov 6, 2013, 8:33:27 AM11/6/13
to altdotne...@googlegroups.com
Direk tıpkısının aynısı sorulmuş, tıpkısının aynısı cevaplanmış...

Nazli Purde Savul

unread,
Nov 6, 2013, 8:35:37 AM11/6/13
to altdotne...@googlegroups.com
ancak burada herhangi bir arrayın içine atamıyorum benim için önemli olan onu bir aaray içerisinde tutmak


2013/11/6 Arda Çetinkaya <ardace...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "altdotnetturkiye" group.
To unsubscribe from this group and stop receiving emails from it, send an email to altdotnetturki...@googlegroups.com.
To post to this group, send email to altdotne...@googlegroups.com.
Visit this group at http://groups.google.com/group/altdotnetturkiye.
For more options, visit https://groups.google.com/groups/opt_out.

Nazli Purde Savul

unread,
Nov 6, 2013, 9:08:15 AM11/6/13
to altdotne...@googlegroups.com
package javaexcelread;

import java.io.File;
import java.io.IOException;

import java.util.ArrayList;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class NewExcel 
{
 
    private String inputFile;
    public String k;
    public int n;

    /**
     *
     */
    public int [][] M;
    public void setInputFile(String inputFile) 
    {
        this.inputFile = inputFile;
    }

    public void read() throws IOException  
    {
        File inputWorkbook = new File(inputFile);
        Workbook w;
        try 
        {
            w = Workbook.getWorkbook(inputWorkbook);
            // Get the first sheet
            Sheet sheet = w.getSheet(0);
            // Loop over first 10 column and lines

            for (int j = 0; j < sheet.getColumns(); j++) 
            {
                for (int i = 0; i < sheet.getRows(); i++) 
                {
                    Cell cell = sheet.getCell(j, i);
                    k= cell.getContents();
                    
                            n= Integer.parseInt(k);
                            M[j][i]=n;
                    
                     System.out.print(M[j][i]);
                    //System.out.print(cell.getContents);
                }
                System.out.println();
            }
        } 
        catch (BiffException e) 
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException 
    {
        NewExcel test = new NewExcel();
        test.setInputFile("C:\\Users\\Administrator\\Desktop\\TEZZZZ\\excelverileri\\ZEMIN.xls");
        test.read();
    }

}

Array ekleyince null pointer exception veriyor sebebi ne olabilir?


2013/11/6 Nazli Purde Savul <nazli...@gmail.com>

Ahmet Arslan

unread,
Nov 6, 2013, 10:26:38 AM11/6/13
to altdotne...@googlegroups.com
Merhaba ;
Hiç java ile kod yazmadım ama diziyi üretmeyi unutmuşsun.
    public int [][] M;
komutuyla sadece bu tipte bir dizin olduğunu belirtiyorsun, bu dizini üretmen gerek. 
c# da
byte[] dizi = new byte[100] ;
diyoruz yani uzunlukları verip üretiyoruz senin de öyle yapman gerektiğini düşünüyorum.

Nazli Purde Savul

unread,
Nov 7, 2013, 2:56:06 AM11/7/13
to altdotne...@googlegroups.com
denedim ancak null pointer exceptiion veriyor


2013/11/6 Ahmet Arslan <arslana...@gmail.com>

Ahmet Arslan

unread,
Nov 7, 2013, 3:29:40 AM11/7/13
to altdotne...@googlegroups.com
Nasıl ekledin, kodu buraya yazar mısın?


--
You received this message because you are subscribed to a topic in the Google Groups "altdotnetturkiye" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/altdotnetturkiye/NU00QeM6d6s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to altdotnetturki...@googlegroups.com.

Ahmet Arslan

unread,
Nov 7, 2013, 3:33:16 AM11/7/13
to altdotne...@googlegroups.com
Tahminim kodun içine bunu koymayı unuttun
M= new int sheet.getColumns()][sheet.getRows()];


bu satırı  "// Loop over first 10 column and lines" satırından hemen sonra koy, sorunun düzeleceğini düşünüyorum. Elimde derleyici yok o yüzden bir şey diyemeyeceğim.

Nazli Purde Savul

unread,
Nov 7, 2013, 3:34:57 AM11/7/13
to altdotne...@googlegroups.com
oldu çok teşekkürler :)


2013/11/7 Ahmet Arslan <arslana...@gmail.com>
Reply all
Reply to author
Forward
0 new messages