supercsv

Retrieve row number with supercsv

随声附和 提交于 2021-01-28 11:59:20
问题 Is there a way with the super-csv library to find out the row number of the file that will be processed? In other word, before i start to process my rows with a loop: while ((obj = csvBeanReader.read(obj.getClass(), csvModel.getNameMapping(), processors)) != null) { //Do some logic here... } Can i retrieve with some library class the number of row contained into the csv file? 回答1: No, in order to find out how many rows are in your CSV file, you'll have to read the whole file with Super CSV

csv 导出数据

偶尔善良 提交于 2020-03-18 18:29:51
3 月,跳不动了?>>> super-csv 版 ①依赖 <dependency> <groupId>net.sf.supercsv</groupId> <artifactId>super-csv</artifactId> <version>2.4.0</version> </dependency> ②代码 package com.mybatis.springbootmybatis.util; import jdk.nashorn.internal.runtime.GlobalConstants; import org.supercsv.io.CsvBeanWriter; import org.supercsv.io.ICsvBeanWriter; import org.supercsv.prefs.CsvPreference; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URLEncoder; import java.time.LocalDateTime; import java.time.format

Parsing Strings in SuperCSV

[亡魂溺海] 提交于 2020-01-24 13:09:05
问题 @Carlo V. Dango I have simplified my question and I have read the documentation--good advice not to panic. Still, I have problems. Help me solve one and it will solve them all. Thank you. Question: When I have a csv record that is missing a non-String field, how (or even can I) convert the missing entry to a default value, or at least, not throw NullPointerException? Optional cellProcessor doesn't appear to prevent the error either. This the program taken essentially from the SuperCSV website

csv to pojo with another pojo

徘徊边缘 提交于 2020-01-15 11:06:13
问题 Orgnization{ private String name; private String uniqueId; private boolean selfRegEnabled; private List<Address> addrList; public void setAddress(Address a){..} public void setName(String name){..} } Addess{ private String type; private String line1; private String line2; private String line3; private String city; private String state; private String zip; private String country; } CSV Header Columns are as below System.UniqueID,Name,EnableSelf-Registration,Addr1.Type,Addr1.Line1,Addr1.Line2

SuperCSV append rather than overwrite?

倾然丶 夕夏残阳落幕 提交于 2020-01-04 14:28:07
问题 Is it possible to add new lines to a CSV file, rather than overwrite the last one? Here is my method I call when I want to add a new line: private static void writeWithCsvMapWriter() throws Exception { final String[] header = new String[] { "Engineer", "Time/Date", "Project", "Test ID", "Data Centre", "Data Hall", "Row", "Grille", "I/S" }; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd_HH:mm:ss"); String currentDateandTime = sdf.format(new Date()); final Map<String, Object> NewRow =

super csv nested bean

谁说我不能喝 提交于 2019-12-31 05:35:08
问题 I have a csv id,name,description,price,date,name,address 1,SuperCsv,Write csv file,1234.56,28/03/2016,amar,jp nagar I want to read it and store it to json file. I have created two bean course(id,name,description,price,date) and person(name,address) on reading by bean reader i'm not able to set the person address. The (beautified) output is Course [id=1, name=SuperCsv, description=Write csv file, price=1234.56, date=Mon Mar 28 00:00:00 IST 2016, person=[ Person [name=amar, address=null],

OpenCSV - How to map selected columns to Java Bean regardless of order?

心已入冬 提交于 2019-12-28 02:51:09
问题 I have a CSV file with the following columns: id , fname , telephone , lname , address . I have a Person class with id , fname and lname data members. I want to map only these columns to Person object from a CSV file and discard telephone and address columns. How can I do this? The solution must scale as more columns are added in future. And should work regardless of column position. In an ideal solution user will only specify columns to read and it should just work. 回答1: You can use

Using SuperCsv with multiple variable columns

a 夏天 提交于 2019-12-22 09:57:08
问题 I was looking at this example from the Super CSV website which shows that dateofbirth is optional column. What happens if i have more than one optional columns? How will the code change than? private static void readVariableColumnsWithCsvListReader() throws Exception { final CellProcessor[] allProcessors = new CellProcessor[] { new UniqueHashCode(), // customerNo (must be unique) new NotNull(), // firstName new NotNull(), // lastName new ParseDate("dd/MM/yyyy") }; // birthDate final

Using SuperCSV to Change Header Values

让人想犯罪 __ 提交于 2019-12-21 18:36:11
问题 In line with this post about abilities of SuperCSV, can SuperCSV handle changing the values of the headers( column names only ) read from the database? For example, the following code snippet details the Current State and the Expected State. Current State INPUT : final String[] header = new String[] { "firstName", "lastName", "birthDate"}; // write the header beanWriter.writeHeader(header); // write the beans for( final CustomerBean customer : customers ) { beanWriter.write(customer, header,

SuperCSV quote every exported cell

纵然是瞬间 提交于 2019-12-14 01:24:02
问题 I'm using superCSV for exporting bean data to CSV. I'd like every cell double quoted, not just the ones with special characters. Now, using CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE, even the cells with special characters won't get quoted. (With EXCEL_PREFERENCE setting the addresses that contain '.' get quoted.) My goal is to export addresses, phone numbers, everything in a way that MS Office (Hungarian) can use and i.e. won't convert phone numbers like +36000000000 to 36000000000. 回答1: