Java Integration

It is easy to use the GoodGrids API with Java to convert CSV files into Excel spreadsheets. You can create an Excel file from a CSV file with this simple snippet of code:

@Test
public void convertCSVToExcelUsingGoodGrids()
  throws ClientProtocolException, IOException
  {
    CloseableHttpClient client = HttpClients.createDefault();
    String goodGridsAPIUrl = "https://api.goodgrids.com/api/convert/v1/csv-to-excel/3a6c0d9ac7c74d";
    HttpPost httpPost = new HttpPost(goodGridsAPIUrl);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("file", new File("to_convert.csv"),
      ContentType.APPLICATION_OCTET_STREAM, "to_convert.csv");

    HttpEntity multipart = builder.build();
    httpPost.setEntity(multipart);

    CloseableHttpResponse response = client.execute(httpPost);
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    client.close();
}

Make sure to set goodGridsAPIUrl to the API URL of the CSV-to-Excel conversion configuration you want to use.

This snippet of code uses the Apache HttpClient 4 for the API request. You can adapt this code to use whichever client library you want.

Found a bug? Have a suggestion on how to improve this documentation? Please send us a note at support@goodgrids.com.

Print