Java Code Examples for net.sf.jasperreports.engine.util.JRLoader#getLocationInputStream()

The following examples show how to use net.sf.jasperreports.engine.util.JRLoader#getLocationInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XChartApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	Map<String, Object> parameters = new HashMap<String, Object>();
	try
	{
		JRCsvDataSource xyds = new JRCsvDataSource(JRLoader.getLocationInputStream("data/xyDatasource.csv"), "UTF-8");
		xyds.setRecordDelimiter("\r\n");
		xyds.setUseFirstRowAsHeader(true);
		parameters.put("xyDatasource", xyds);
	}
	catch (Exception e)
	{
		throw new JRException(e);
	}
	JasperFillManager.fillReportToFile("build/reports/XYChart.jasper", new HashMap<String, Object>(parameters), new JREmptyDataSource());
	System.err.println("Filling time : " + (System.currentTimeMillis() - start));
}
 
Example 2
Source File: XlsDataSourceApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
	 *
	 */
	private static ExcelDataSource getDataSource() throws JRException
	{
		ExcelDataSource ds;
		
		try
		{
			String[] columnNames = new String[]{"city", "id", "name", "address", "state"};
			int[] columnIndexes = new int[]{0, 2, 3, 4, 5};
			ds = new ExcelDataSource(JRLoader.getLocationInputStream("data/XlsDataSource.data.xls"));
//			ds.setUseFirstRowAsHeader(true);
			ds.setColumnNames(columnNames, columnIndexes);
			
			//uncomment the below line to see how sheet selection works
//			ds.setSheetSelection("xlsdatasource2");
		}
		catch (Exception e)
		{
			throw new JRException(e);
		}
		
		return ds;
	}
 
Example 3
Source File: SpiderChartApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	
	JRCsvDataSource cds = null;
	try
	{
		String[] columnNames = new String[]{"value", "series", "category"};

		cds = new JRCsvDataSource(JRLoader.getLocationInputStream("data/spiderDatasource.csv"), "UTF-8");
		cds.setRecordDelimiter("\n");
		cds.setUseFirstRowAsHeader(false);
		cds.setColumnNames(columnNames);
	}
	catch (UnsupportedEncodingException e)
	{
		throw new JRException(e);
	}
	
	JasperFillManager.fillReportToFile("build/reports/SpiderChart.jasper", null, cds);
	System.err.println("Filling time : " + (System.currentTimeMillis() - start));
}
 
Example 4
Source File: XlsxDataSourceApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
	 *
	 */
	private static JRXlsxDataSource getDataSource() throws JRException
	{
		JRXlsxDataSource ds;
		
		try
		{
			String[] columnNames = new String[]{"city", "id", "name", "address", "state", "date"};
			int[] columnIndexes = new int[]{0, 2, 3, 4, 5, 6};
			ds = new JRXlsxDataSource(JRLoader.getLocationInputStream("data/MultisheetXlsxDataSource.data.xlsx"));
//			ds.setUseFirstRowAsHeader(true);
			ds.setColumnNames(columnNames, columnIndexes);
//			ds.setSheetName("XlsxDataSource3");
		}
		catch (IOException e)
		{
			throw new JRException(e);
		}
		
		return ds;
	}