# Import Excel .xlsx to Processing

**URL:** <https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816>\
**Category:** Coding Questions\
**Created:** [March 31, 2019, 6:44pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816 "2019-03-31T18:44:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![angel96](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@angel96](https://discourse.processing.org/u/angel96)\
**Post date:** [March 31, 2019, 6:44pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/1 "2019-03-31T18:44:27Z")

</div>

Hello!  
I have a problem about importing an excel file into processing. I followed this guide: [Private Site](https://conorblack.wordpress.com/2014/03/23/export-import-processing-excel-xlsx/)  
but in `importExcel()`, at this line:

```auto
Sheet sheet = wb.getSheetAt(0);

```

show me an error:

> NullPointException.

How I solve this problem?  
Help me! Please  
Thank you all

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 31, 2019, 9:30pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/2 "2019-03-31T21:30:54Z")

</div>

This probably means that wb has not loaded a spreadsheet, so the sheets list is null (there is no sheet 0). Perhaps your file is in the wrong place, or invalid, or is a version of excel that doesn’t work with this excel import code written before 2014.

On the page you linked there are comments. Someone had the same problem as you, and someone else suggested a way of formatting the file path. The file path format depends on whether you are on Mac or Windows, however.

The “solution” comment has been autoformatted with smart quotes (curly) – breaking it. you will need to change them into straight quotes before trying it.

Beyond that, hard to know without seeing your code.

---

<div class="post-metadata">

**Author:** ![angel96](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@angel96](https://discourse.processing.org/u/angel96)\
**Post date:** [April 1, 2019, 1:53pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/3 "2019-04-01T13:53:53Z")

</div>

Thank you so much for the answer!  
I followed the suggestion in the comment, but couldn’t solve the problem.

 ![Cattura1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/aa8eaa5e57307385fe8fc144f167899bda998380.png)

I have tried to write only the name of the Excel file, but it show me the error.  
If I write the file path as described in the comment, it marks an error: Not expecting symbol ‘U’, which is LATIN CAPITAL LETTER U.

This is my code in importExcel():

```auto
SXSSFWorkbook swb=null;
Sheet sh=null;
InputStream inp=null;
Workbook wb=null;

String[][] importExcel(String filepath) {
  String[][] temp;
  try {
    inp = new FileInputStream(filepath);
  }
  catch(Exception e) {
  }
  try {
    wb = WorkbookFactory.create(inp);
  }
  catch(Exception e) {
  }
  Sheet sheet = wb.getSheetAt(0);
  int sizeX = sheet.getLastRowNum()+1;
  int sizeY = 100;
  for (int i=0;i<sizeX;++i) {
    Row row = sheet.getRow(i);
    for (int j=0;j<sizeY;++j) {
      try {
        Cell cell = row.getCell(j);
      }
      catch(Exception e) {
        if (j>sizeY) {
          sizeY = j;
        }
      }
    }
  }
  temp = new String[sizeX][sizeY];
  for (int i=0;i<sizeX;++i) {
    for (int j=0;j<sizeY;++j) {
      Row row = sheet.getRow(i);
      try {
        Cell cell = row.getCell(j);
        if (cell.getCellType()==0 || cell.getCellType()==2 || cell.getCellType()==3)cell.setCellType(1);
        temp[i][j] = cell.getStringCellValue();
      }
      catch(Exception e) {
      }
    }
  }
  println("Excel file imported: " + filepath + " successfully!");
  return temp;
}

```

I don’t know how to solve this problem. What do you suggest me?  
Thank a lot.

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [April 1, 2019, 2:34pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/4 "2019-04-01T14:34:24Z")

</div>

Hi Angel96, on what system are you working?

because in Windows you must use backslash escapes for writing literal path:

```auto
String path = "C:\\Users\\Dennis\\Videos";

```

---

<div class="post-metadata">

**Author:** ![angel96](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@angel96](https://discourse.processing.org/u/angel96)\
**Post date:** [April 1, 2019, 5:13pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/5 "2019-04-01T17:13:59Z")

</div>

Dennis thank you a lot, I was able to solve the problem of reading the excel file, with your suggested.  
I didn’t think of writing the path for how you suggested to me.  
How should write the path on mac?  
thank you very much to both

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [April 1, 2019, 8:19pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/6 "2019-04-01T20:19:13Z")

</div>

Mhh… Now I can’t try but Tomorrow night I will do it on my iMac…

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [April 3, 2019, 7:58pm UTC](https://discourse.processing.org/t/import-excel-xlsx-to-processing/9816/7 "2019-04-03T19:58:15Z")

</div>

Hi, sorry for lag response…  
This is path in OS X

```auto
String path = "/Users/Dennis/Downloads/Processing.app"

```

keep us update
