usermodel is accessible from more than one module poi, poi.examples - apache

I am getting an error on lines 9, 11, 13, 15 17 - The package org.apache.poi.hssf.usermodel is accessible from more than one module poi, poi.examples. I downloaded the latest poi jars and added them to module path. Please let me know where I went wrong?
package apachetests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Writetoexcel {
public static void main(String []args){
try {
// Specify the file path which you want to create or write
File src=new File("C:\\Users\\Venkat\\Desktop\\Hima2017\\Names.xlsx");
// Load the file
FileInputStream fis=new FileInputStream(src);
// load the workbook
XSSFWorkbook wb=new XSSFWorkbook(fis);
// get the sheet which you want to modify or create
XSSFSheet sh1= wb.getSheetAt(0);
// getRow specify which row we want to read and getCell which column
System.out.println(sh1.getRow(0).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(0).getCell(1).getStringCellValue());
System.out.println(sh1.getRow(1).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(1).getCell(1).getStringCellValue());
System.out.println(sh1.getRow(2).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(2).getCell(1).getStringCellValue());
// here createCell will create column
// and setCellvalue will set the value
sh1.getRow(0).createCell(2).setCellValue("2.41.0");
sh1.getRow(1).createCell(2).setCellValue("2.5");
sh1.getRow(2).createCell(2).setCellValue("2.39");
// here we need to specify where you want to save file
FileOutputStream fout=new FileOutputStream(new File("location of file/filename.xlsx"));
// finally write content
wb.write(fout);
// close the file
fout.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

This is solved with the latest release.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>

Related

FlatFileParseException Parsing class path resource error in spring batch

I want to set classPath resource of csv file . Which is present in my
project resource folder. When set the class Path and run the project I
get issue in runtime issue of classpath resource
here is the issue
org.springframework.batch.item.file.FlatFileParseException: Parsing error at line: 1 in resource=[class path resource [result-match-metadata.csv]], input=[id city date player_of_match venue neutral_venue team1 team2 toss_winner toss_decision winner result result_margin eliminator method umpire1 umpire2]
result-match-metadata.csv file is present inside my resource folder
Batchconfig.kt
package com.nilmani.dashboardipl.data
import com.nilmani.dashboardipl.entity.Match
import org.springframework.batch.core.Job
import org.springframework.batch.core.Step
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory
import org.springframework.batch.core.launch.support.RunIdIncrementer
import org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider
import org.springframework.batch.item.database.JdbcBatchItemWriter
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder
import org.springframework.batch.item.file.FlatFileItemReader
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.io.ClassPathResource
import javax.sql.DataSource
#Configuration
#EnableBatchProcessing
class BatchConfig {
#Autowired
private lateinit var jobBuilderFactory: JobBuilderFactory
#Autowired
private lateinit var stepBuilderFactory: StepBuilderFactory
val FIELD_NAMES = arrayOf(
"id","city","date","player_of_match","venue","neutral_venue",
"team1","team2","toss_winner","toss_decision",
"winner","result","result_margin","eliminator","method","umpire1","umpire2"
)
#Bean
fun reader(): FlatFileItemReader<MatchInput> {
return FlatFileItemReaderBuilder<MatchInput>()
.name("MatchItemReader")
.resource(ClassPathResource("result-match-metadata.csv"))
.delimited()
.names(*FIELD_NAMES)
.fieldSetMapper(object : BeanWrapperFieldSetMapper<MatchInput>() {
init {
setTargetType(MatchInput::class.java)
}
})
.build()
}
}
how to set csv file path in batch config
The resource is correctly found. The error means that the first line cannot be mapped to an instance of MatchInput. You just need to skip the header with FlatFileItemReaderBuilder#linesToSkip(1) in your item reader definition.

Adding Apache POI 4.0.1 library not sufficient to use XSSFWorkbook

I am using the following tutorial to realize a Selenium Keyword Driven Framework : http://toolsqa.com/selenium-webdriver/keyword-driven-framework/set-excel-apache-poi/
For the part which ask to create an "util" package with an ExcelUtils class, I followed the instructions which begin by adding a jar to the project libraries.
This jar is for the library apache-poi-4.0.1 : poi-4.0.1.jar.
But even with this library and it's attached source, classes XSSFWorkbook, XSSFSheet and XSSFCell do not exist.
So my question is, which part of the tutorial I am missing? Or which library I am missing?
I am using Eclipse Oxygen with the JRE JavaSE-1.8
Package utils;
import java.io.FileInputStream;
public class ExcelUtils {
private static XSSFSheet ExcelWSheet;
private static XSSFWorkbook ExcelWBook;
private static XSSFCell Cell;
//This method is to set the File path and to open the Excel file
//Pass Excel Path and SheetName as Arguments to this method
public static void setExcelFile(String Path,String SheetName) throws Exception {
FileInputStream ExcelFile = new FileInputStream(Path);
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
}
//This method is to read the test data from the Excel cell
//In this we are passing parameters/arguments as Row Num and Col Num
public static String getCellData(int RowNum, int ColNum) throws Exception{
Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
String CellData = Cell.getStringCellValue();
return CellData;
}
}
You are missing the below piece of code
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
I finally found a solution.
I had to download 5 other libraries :
poi-examples-4.0.1
poi-excelant-4.0.1
poi-ooxml-4.0.1
poi-ooxml-schemas-4.0.1
poi-scratchpad-4.0.1
After that, I can use XSSF classes.
You need the poi-ooxml dependency as well.
This is how it looks in Gradle, just change $apachePoiVersion to the version you want.
implementation "org.apache.poi:poi:$apachePoiVersion"
implementation "org.apache.poi:poi-ooxml:$apachePoiVersion"

(Monte Media Library) Record screen im mp4 format

Below is Monte Media Library.
http://www.randelshofer.ch/monte/
I am using MonteScreenRecorder jar for record screen.
I am able to store video file in avi format but i want to store in mp4 format
Here is code for avi
import java.awt.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.monte.media.Format;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;
import static org.monte.media.VideoFormatKeys.*;
...
private ScreenRecorder screenRecorder;
public void startRecording() throws Exception
{
GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration();
this.screenRecorder = new ScreenRecorder(gc,
new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
DepthKey, 24, FrameRateKey, Rational.valueOf(15),
QualityKey, 1.0f,
KeyFrameIntervalKey, 15 * 60),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black",
FrameRateKey, Rational.valueOf(30)),
null);
this.screenRecorder.start();
}
public void stopRecording() throws Exception
{
this.screenRecorder.stop();
}
...
What are the change is required let me know.
Please Help
Thank you

SVG to PDF: PDFTranscoder convert only part of file

I use this code for convert SVG to PDF:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.fop.svg.PDFTranscoder;
public class SVGtoPDF{
public static void main(String[] argv) throws TranscoderException, FileNotFoundException {
Transcoder transcoder = new PDFTranscoder();
TranscoderInput transcoderInput = new TranscoderInput(new FileInputStream(new File("/tmp/test.svg")));
TranscoderOutput transcoderOutput = new TranscoderOutput(new FileOutputStream(new File("/tmp/test.pdf")));
transcoder.transcode(transcoderInput, transcoderOutput);
}
}
And this is working but little bit strange
This code convert to pdf only part of file - right top quarter
Somebody know why? And how to solve
Thanks

JSLint4Java usage

JSLint4Java is a Java wrapper for JSLint. I need something like this for use in my GWT project, but the only way to use JSLint4Java seems to be from command line or with an ANT task. Does anyone know if there is any way to just import the JARs and use them in a project? When I try adding them to the GWT WAR folder, I get lots of errors like 'xxx cannot be resolved to a type'.
Thanks.
Yes you can import the jar and use it like this :
import com.googlecode.jslint4java.Issue;
import com.googlecode.jslint4java.JSLint;
import com.googlecode.jslint4java.JSLintBuilder;
import com.googlecode.jslint4java.JSLintResult;
public static void lint(final String filePath) throws FileNotFoundException, IOException {
String fileContent = Streams.read(new FileInputStream(new File(filePath))));
JSLintBuilder builder = new JSLintBuilder();
JSLint jsLint = builder.fromDefault();
JSLintResult result = jsLint.lint("test.js", fileContent);
for (Issue issue : result.getIssues()) {
System.out.println(issue.toString());
}
}