Skip to main content

Posts

Showing posts with the label csv

Writing data from my app to csv & upload it?

I wondered if it's possible to write some data to csv file in the documents path, or other convenient readable file. For example - i have a few text fields that i want the user to fill & then i want him to click "send" & after that the information will be written on a file that i could easily read & upload to my server. In my case i have an app that i want people to register for my members club, with first name, last name & phone number & i want to take this information & read it easily after is uploaded to my server. For testing i'm using my dropbox account as a server. Is it possible? Thanks for the help :)

Splitting a CSV into an object with javascript/jquery

I have an ordered array which looks like this:- [-0.0020057306590257895, 50, 0.09598853868194843, 50, 0.19398280802292264, 49.99999999999999, 0.2919770773638969, 50] What I would like to do is the following: Take each 'odd' entry and make it the 'key index in an object, which can be achieved by rounding the value and multiplying by 10 e.g. (Math.round(-0.0020057306590257895 * 10) should be index 0 and Math.round(0.09598853868194843 * 10) should be index 1 etc) Take the 'even' values and make them the corresponding values in the object. So... The above CSV file should return the following object:- { 0: 50, 1: 50, 2: 49.99999999999999, 3: 50 } Does anyone one know how I can parse this CSV to produce the required array using either jQuery or plain javascript?

Writing CSV file. myPackage.MyClass cannot be cast to java.lang.CharSequence

I need to write List<MyClass> myList into CSV file. In particular I need to write values . MyClass has the following implementation: public class MyClass { private Object[] values; //... @Override public String toString() { String line = ""; for (int i=0; i<this.getSize(); i++) { //if (this.values[i] != null) { line = line + this.values[i] + " "; //} } return line; } } The code is the following: private void saveSolutionToCSV(List<MyClass> solution) { int columnSize = solution.get(0).getSize(); try { FileWriter writer = new FileWriter("test.csv"); Iterator result = solution.iterator(); while(result.hasNext()) { for(int i = 0; i < columnSize; i++) { CharSequence element = (CharSequence)result.next(); writer.append(element); if(i < columnSize - 1) writer.a

UTF-8 problems while reading CSV file with fgetcsv

I try to read a CSV and echo the content. But the content displays the characters wrong. Mäx Müstermänn -> Mäx Müstermänn Encoding of the CSV file is UTF-8 without BOM (checked with Notepad++). This is the content of the CSV file: "Mäx";"Müstermänn" My PHP script <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <?php $handle = fopen ("specialchars.csv","r"); echo '<table border="1"><tr><td>First name</td><td>Last name</td></tr><tr>'; while ($data = fgetcsv ($handle, 1000, ";")) { $num = count ($data); for ($c=0; $c < $num; $c++) {