Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • How to append row to .xlsx excel file?

    I have this code, and it create the new file if not exists.. but when file exists no add row.. any solution? Thanks in advice.

    `import java.io.*;

    void setup() { StringList data = new StringList(); data.append("uno"); data.append("dos"); data.append("tres"); data.append("cuatro"); data.append("cinco"); data.append("seis"); writeAppendExcel q; q = new writeAppendExcel(); q.writeExcel(dataPath("test.xls"), data); } void draw() {

    } class writeAppendExcel{
    public void writeExcel(String fileName, StringList params) {
    File myFile = new File(fileName);
    FileInputStream inputFileStream_ = null;
    HSSFWorkbook myBook = null;
    HSSFSheet mySheet = null;
    FileOutputStream outputFileStream_ = null;
    POIFSFileSystem lPOIfs = null;

        if (myFile.exists()) {   
    
          try {   
              outputFileStream_ = new FileOutputStream(fileName, true);   
              inputFileStream_ = new FileInputStream(fileName);   
              lPOIfs = new POIFSFileSystem(inputFileStream_);   
              myBook = new HSSFWorkbook(lPOIfs);   
              mySheet = myBook.getSheet("hoja01");   
              } catch (IOException e) {   
                  e.printStackTrace();   
              }   
        }   
        else {   
               // Create new file   
            try {   
                 outputFileStream_ = new FileOutputStream(fileName, true);   
            } catch (FileNotFoundException e) {   
                e.printStackTrace();   
            }   
            myBook = new HSSFWorkbook();   
            mySheet = myBook.createSheet("hoja01");   
        }   
        try {   
            for(int t=0; t<1000; t++){
                HSSFRow fila = mySheet.createRow(mySheet.getLastRowNum()+1);
                for ( int i=0; i<params.size(); i++ ) {   
                    HSSFCell celda = fila.createCell( i );
                    celda.setCellValue( params.get(i) );
                }
            }
            myBook.write(outputFileStream_);   
            outputFileStream_.flush();
    
        }   
        catch (IOException e) {   
            e.printStackTrace();   
        }   
        finally {   
            try {   
                outputFileStream_.close(); 
                exit();
            }   
            catch (IOException e) {   
                e.printStackTrace();   
            }          
        }   
    }
    

    } `

  • How to automate Rhino/grasshoper workflow with processing?

    This post shows a way to access a spreadsheet: https://forum.processing.org/two/discussion/20053/hivis-sketch-pulling-xlsx-file-gives-nullpointerexception/p1

    What to do next is really based on your design and needs. Please provide a MCVE showing your approach if you get stuck.

    Kf

  • HiVis sketch pulling xlsx file gives NullPointerException?

    Thanks for the suggestions; the new File reference didn't work even when I used the proper full path (pulled from the terminal window, even) - still not sure why it didn't work.

    Printing the value of data.Length() didn't work because it would hang (nullPointerException) before getting to that step. I ended up adjusting the sketch so that the data.Length() value is assigned a to an int variable in the setup section, and then used that variable later, which worked great.

    Here's the now-working code:

    import hivis.common.*;
    import hivis.data.*;
    import hivis.data.reader.*;
    import hivis.data.view.*;
    import hivis.example.*;
    
    // Pulls coordinate info from a spreadsheet and draws the coordinates as white dots on a black 180 x 180 square. 
    
    // Stores the data to plot.
    DataTable data;
    
    // The series containing the data we want to plot.
    DataSeries xSeries;
    DataSeries ySeries;
    int sslength;
    
    
    // Method containing one-off setup code.
    void setup() {
      // Make a canvas that is 180 pixels wide by 180 pixels high.
      size(180, 180);
      // Pull a spreadsheet from the sketch/data folder.
    
      int sheet = 0;
      int headerRow = 0;
      int firstDataRow = 1;
      int firstDataColumn = 0;
      DataTable data = HV.loadSpreadSheet(sketchFile("center_coord100_2.xlsx"), sheet, headerRow, firstDataRow, firstDataColumn);
      // The series containing the data we want to plot.
      xSeries = data.getSeries(1);
      ySeries = data.getSeries(2);
      sslength = data.length();
    }
    
    
    
    // Draws the plot.
    void draw() {
      background(0);
    
      // If the data is ready to plot.
      if (ySeries != null) {
    
    
        // Gather info from each row.
        for (int row = 0; row < sslength; row++) {
    
          // Get values from the series. 
    
          int x = xSeries.getInt(row);
          int y = ySeries.getInt(row);
    
          // Draw a dot.
          noStroke();
          fill(255);
          ellipse(x, y, 14, 14);
        }
      }
    }
    

    Thanks anyway for the suggestions-

  • HiVis sketch pulling xlsx file gives NullPointerException?

    Ok, looks like I fixed it, needed

    int sheet = 0;
    int headerRow = 0;
    int firstDataRow = 1;
    int firstDataColumn = 0;
    DataTable data = HV.loadSpreadSheet(sketchFile("center_coord100_2.xlsx"), sheet, headerRow, firstDataRow, firstDataColumn);
    

    instead of

    DataTable data = HV.loadSpreadSheet(new File("center_coord100_2.xlsx"));

    still got a nullpointerexception from this line:

    for (int row = 0; row < data.length(); row++) {

    until I changed data.length() to the actual number of the length; would be nice to know why.

    thanks in any case!

  • HiVis sketch pulling xlsx file gives NullPointerException?

    Hi, more or less complete novice here; please point me elsewhere if this is the wrong place to ask...

    Using the HiVis libraries, I'm trying to build a sketch that will pull coordinate info from a spreadsheet in my sketch's data folder and draw dots on a square at those coordinates. I've got a working sketch using selectInput that asks a user to select the xlsx file, but when I sub in the suggested line for pulling a file from the data folder, I get a nullPointerException at that line, java hangs (I have to force quit it) and I get this text:

    Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help → Troubleshooting.

    Any idea what I'm doing wrong?

    I found the suggested lines here (commented out, midway down page): https://github.com/OliverColeman/hivis/blob/latest/examples/examples/HV02_Tables/HV02_Tables.pde

    Broken sketch:

    import hivis.common.*;
    import hivis.data.*;
    import hivis.data.reader.*;
    import hivis.data.view.*;
    import hivis.example.*;
    
    // Pulls coordinate info from a spreadsheet and draws the coordinates as white dots on a black 180 x 180 square. 
    
    // Stores the data to plot.
    DataTable data;
    
    // The series containing the data we want to plot.
    DataSeries xSeries;
    DataSeries ySeries;
    
    // Method containing one-off setup code.
    void setup() {
      // Make a canvas that is 180 pixels wide by 180 pixels high.
      size(180, 180);
      // Pull a spreadsheet from the sketch/data folder.
      DataTable data = HV.loadSpreadSheet(new File("center_coord100_2.xlsx"));
      // The series containing the data we want to plot.
      xSeries = data.getSeries(1);
      ySeries = data.getSeries(2);
    }
    
    
    
    // Draws the plot.
    void draw() {
      background(0);
    
      // If the data is ready to plot.
      if (ySeries != null) {
    
        // Gather info from each row.
        for (int row = 0; row < data.length(); row++) {
    
          // Get values from the series. 
    
          int x = xSeries.getInt(row);
          int y = ySeries.getInt(row);
    
          // Draw a dot.
          noStroke();
          fill(255);
          ellipse(x, y, 14, 14);
        }
      }
    }
    

    Working sketch:

    import hivis.common.*;
    import hivis.data.*;
    import hivis.data.reader.*;
    import hivis.data.view.*;
    import hivis.example.*;
    
    // Pulls coordinate info from a spreadsheet and draws the coordinates as dots on a 180 x 180 square. 
    
    // Stores the data to plot.
    DataTable data;
    
    // The series containing the data we want to plot.
    DataSeries xSeries;
    DataSeries ySeries;
    
    // Method containing one-off setup code.
    void setup() {
      // Make a canvas that is 180 pixels wide by 180 pixels high.
      size(180, 180);
      // Ask the user to select a spreadsheet to visualise.
      selectInput("Select an excel file to visualise:", "fileSelected");
    }
    
    
    // Method that gets called when a file is selected.
    void fileSelected(File selection) {
      // If no file was selected.
      if (selection == null) {
        println("No file selected.");
      } else {
        // Get data from spread sheet. 
        // The SpreadSheetReader will automatically update the DataTable it provides if the source file is changed.
        data = HV.loadSpreadSheet(selection);
    
        // Get the series containing the data we want to plot. 
        xSeries = data.getSeries(1);
        ySeries = data.getSeries(2);
      }
    }
    
    
    // Draws the plot.
    void draw() {
      background(0);
    
      // If the data is ready to plot.
      if (ySeries != null) {
    
        // Gather info from each row.
        for (int row = 0; row < data.length(); row++) {
    
          // Get values from the series. 
    
          int x = xSeries.getInt(row);
          int y = ySeries.getInt(row);
    
       // Draw a dot.
          noStroke();
          fill(255);
          ellipse(x, y, 14, 14);
        }
      }
    }
    

    Thank you!!

  • Need help in reading xlsx table directly (without converting to CSV)?

    If you have a static xlsx file with three different tables in it, why not save three different csv files -- one for each table -- using Excel > Save As > CSV?

    Then use loadTable() in your sketch.

    I'd have more specific advice, but I don't know what your data is or what your sketch is trying to do with it.

  • Need help in reading xlsx table directly (without converting to CSV)?

    Thank you Jeremy, I totaly agree, in my case the xlsx file has 3 tables on one spreadsheet, i'll try saving full file as csv.

    I found https://github.com/SheetJS/js-xlsx is it possible to use it in p5.js ?

  • Need help in reading xlsx table directly (without converting to CSV)?

    This question is asked periodically on the forum, but seldom answered.

    That silence may be because parsing xlsx directly rather than exporting / converting them is almost always a lot of work and usually a bad idea -- xlsx files can be really, really complicated and difficult to read, and there are many ways they can fail.

    There was a sketch for Processing 2 (not Processing 3 or p5.js) that did this.

    https://conorblack.wordpress.com/2014/03/23/export-import-processing-excel-xlsx/

    See also the XlsReader library in the Processing 2 (not 3) contribution manager and on github:

    https://github.com/fjenett/xlsreader-library-processing

    However, if you are trying to work with xlsx files and p5.js, better advice might be to run a csv conversion script (doesn't have to be processing) separately (e.g. on upload) and then run the sketch on the csv file.

  • Need help in reading xlsx table directly (without converting to CSV)?

    Hi all,

    I am lost on google trying to find an example, am using p5.js (not expert). If you can help in small example and what library i need to use?

    Appreciate your help, Firas.

  • Question about Excel

    I want to put the parameter from arduino to the excel.

    1.The XlsReader in the Homepage can not be used in the latest processing version,i put that in the library file, but dosen't work.Should i download the old version,or someone can help?

    2.I also tried the other way, such like using the code from this web.

    https://conorblack.wordpress.com/2014/03/23/export-import-processing-excel-xlsx/ But could someone show me some simple examples, to use this code.

    Thx a lot~~

  • Reading xlsx files with xls reader

    I can't figure out how to read .xlsx files extension with xls reader. Is it possible, or does the library only work with .xls files?

  • xlsreader and excel 2010 (xlsx files)

    Is it possible to use xlsreader with XLSX files, and if it is, how do I do, because I can't not figure out how to make it work.

  • loadFont is not defined

    Ok i got it. It was a few things going wrong creating the perfect storm of issues.

    1. I was using firefox which allows for local loading of data files (using xlsx loading lib)
    2. The CDN/Bower (and I think the downloaded version) were giving out of date versions. Not sure what was going on here, but they didn't have the loadFont method.
    3. When I finally got a lib with the loadfont, the font file I was using was corrupt or something (ttf version failed with the "RangeError" the otf worked.)

    Any thoughts on why loadfont would be missing from some places but not others?

    Thanks for the help GoTo loop! (no thanks to Xxpr0sesserg0dxX :P )

  • Import & Export Excel .xlsx to Processing

    Hi there.

    http://conorblack.wordpress.com/2014/03/23/export-import-processing-excel-xlsx/

    This is a link to [not a library], but to a simple sketch that has two functions that utilises apache poi to import & export to excel .xlsx files.

    For import: it simply converts the imported Excel table to a 2d string array. For export: it [simply again] converts a 2d string array to an Excel file.

    Please try it out :)