Ad
FileWriter Write Html In Single Cell When Creating Csv
I'm working on an app, I want to generate a CSV file, it has many columns with normal text, one of the columns has HTML text
I want to insert HTML text without formatting but with tags, when I open the file in CSV it distorts the formatting due to line breaks and other HTML tags. Below is my code
FileWriter fw = new FileWriter(filename);
// the below is normal string and it's fine
fw.append(selectedProduct.getHandle());
fw.append(",");
// below is html string it doesn't come in single cell
fw.append(selectedProduct.getHTMLBody());
fw.append(",");
I want to show HTML In a single cell like in CSV like below
Any help would be grateful.
Ad
Answer
If you want to get rid of line breaks remove them from the HTML:
fw.append(selectedProduct.getHTMLBody().replaceAll("\\r\\n|\\r|\\n", " "));
Note that your cells are comma separated. The consequence of that is that any comma in your HTML contents will be recognized as cell boundary. To indicate that contents should be single cell try surrounding it with quotes:
fw.append("\"" + selectedProduct.getHTMLBody().replaceAll("\\r\\n|\\r|\\n", " ") + "\"");
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad