如何删除单元格或喜欢以 XLS 格式在页面中心获取报告
How to remove the cells or like to get a report in centre of the page in XLS format
我已经使用 jasper 报告完成了一份报告并且得到了很好的报告,但我担心的是当我打开报告时它以 XLS 格式打开但它完全位于页面的左侧部分,如下所示
我希望报告位于页面的中心,所有多余的单元格,如 'M'、'N'、'O' 都将被删除。
Report.jsp
<body>
<%
String sql=null;
Connection conn = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/marketing_database","root","root");
sql = "select company_profile.companyName AS 'cname',quotationclient_details.RefNo,quotationclient_details.Date,quotationclient_details.CustomerName,quotationclient_details.CompanyName AS 'ccname',quotationclient_details.PaymentTerm,quotationclient_details.DeliveryTime,quotationclient_details.Validity,quotation.Item,quotation.id,quotation.Description,quotation.Quantity,quotation.PerUnitPrice,quotation.TotalPrice,quotation.VAT5,quotation.VAT14,quotation.CST,quotationclient_details.MobileNo,quotation.ServiceTax,company_profile.companyLogo,company_profile.companyLetterHead from quotation,quotationclient_details,company_profile where quotation.CId In (select max(CId) from quotationclient_details) and quotationclient_details.CId In (select max(CId) from quotationclient_details)";
ServletContext context = request.getServletContext();
String fullPath = context.getRealPath("/WEB-INF/reports/report9.jrxml");
InputStream input = new FileInputStream(new File(fullPath));
JasperDesign jasperDesign = JRXmlLoader.load(input);
System.out.println("Compiling Report Designs");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
System.out.println("Creating JasperPrint Object");
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("sql",sql);
JasperPrint jasperPrint = JasperFillManager.fillReport (jasperReport,map,conn);
byte bytes[] = new byte[10000];
//String result = JasperRunManager.runReportToHtmlFile("./usertemplates/test.jasper" , parameters, conn);
JRXlsExporter exporter = new JRXlsExporter();
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, xlsReport);
exporter.exportReport();
//System.out.println("Size of byte array:"+xlsReport.size());
//bytes = xlsReport.toByteArray();
String fileName = "QuotationReport.xls";
response.setHeader("Content-Disposition", "inline; filename="
+ fileName);
response.setContentType("application/vnd.ms-excel");
//System.out.println("After JasperPrint = 1");
response.setContentLength(xlsReport.size());
//System.out.println("After JasperPrint = 2");
//xlsReport.close();
//System.out.println("After JasperPrint = 3");
OutputStream outputStream = response.getOutputStream();
System.out.println("After JasperPrint = 4");
xlsReport.writeTo(outputStream);
outputStream.flush();
//outputStream.close();
}
catch(Exception e)
{e.printStackTrace();}
%>
</body>
report.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report11" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" scriptletClass="com.reporter.jasper.ConvertToWord" uuid="16229028-8f93-4195-966f-09e0c49feb94">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select
company_profile.companyName AS 'cname',
quotationclient_details.RefNo,
quotationclient_details.Date,
quotationclient_details.CustomerName,
quotationclient_details.CompanyName AS 'ccname',
quotationclient_details.PaymentTerm,
quotationclient_details.DeliveryTime,
quotationclient_details.Validity,
quotation.Item,quotation.id,
quotation.Description,
quotation.Quantity,
quotation.PerUnitPrice,
quotation.TotalPrice,
quotation.VAT5,
quotation.VAT14,
quotation.CST,
quotationclient_details.MobileNo,
quotation.ServiceTax,
company_profile.companyLogo,
company_profile.companyLetterHead
from quotation,quotationclient_details,company_profile where quotation.CId In (select max(CId) from quotationclient_details) and quotationclient_details.CId In (select max(CId) from quotationclient_details)]]>
</queryString>
<field name="cname" class="java.lang.String"/>
<field name="RefNo" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Date" class="java.sql.Date">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="CustomerName" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="ccname" class="java.lang.String"/>
<field name="PaymentTerm" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="DeliveryTime" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Validity" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Item" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="id" class="java.lang.Long">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Description" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Quantity" class="java.lang.Long">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="PerUnitPrice" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="TotalPrice" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="VAT5" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="VAT14" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="CST" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="MobileNo" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="ServiceTax" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="companyLogo" class="java.sql.Blob">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="companyLetterHead" class="java.sql.Blob">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="Sub Total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{TotalPrice}]]></variableExpression>
</variable>
<variable name="Output VAT and CST and Service Tax" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{VAT5} +$F{VAT14} +$F{ServiceTax} +$F{CST}]]></variableExpression>
</variable>
<title>
<band height="260" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="25" y="102" width="268" height="20" uuid="f2e6a64d-e30b-4b5d-8ce0-8aa347bf4b24"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{RefNo}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="">
<reportElement x="293" y="102" width="262" height="20" uuid="3fbe0992-ece7-424f-b6e7-100482dcb771"/>
<box>
<topPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="313" y="122" width="242" height="14" isPrintWhenDetailOverflows="true" uuid="91ce3cf8-5ab5-45f1-97ac-92b88d453158"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{CustomerName}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="313" y="136" width="242" height="13" isPrintWhenDetailOverflows="true" uuid="8917fe3e-5ff5-492d-82c4-441701f82f7e"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{ccname}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="313" y="149" width="242" height="13" uuid="246061b8-09fd-4086-a735-146048a7a201"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement markup="none">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement x="313" y="175" width="242" height="20" uuid="c299b4ca-f46e-49ca-8d4f-b3204d06fc89"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement markup="none">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{MobileNo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="195" width="555" height="20" forecolor="#FF0000" uuid="cc2007f5-62a9-4b1c-a204-09566e931526"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="10" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Sub Quotation for supply of UPS and Batteries]]></text>
</staticText>
<staticText>
<reportElement x="10" y="215" width="545" height="45" uuid="3ae6bde4-be3c-40f0-8ac7-ac1274007b22"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Dear Sir,
We thank you for your enquiry and the interest shown in our range of products and services.As per the requirements provided by you,please find here below our revised offer in INR for the same]]></text>
</staticText>
<staticText>
<reportElement x="0" y="122" width="293" height="14" uuid="509840bf-7159-427d-93ff-e4cf88dc48aa"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<text><![CDATA[Contact Person Name:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="136" width="293" height="13" uuid="6a696a9c-830d-46de-9124-f1a5344c30d3"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" size="10" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Company Name:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="149" width="293" height="13" uuid="b9000080-e944-4e1f-a711-378e36c247b5"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Address:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="162" width="293" height="13" uuid="9f8b1f79-c8fd-4a65-9f93-4ce48440045b"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Email:]]></text>
</staticText>
<staticText>
<reportElement x="313" y="162" width="242" height="13" uuid="1eac5333-e70c-4afe-89bc-3fb39a8c9bef"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement markup="none">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<staticText>
<reportElement x="0" y="175" width="293" height="20" uuid="7ecaa5cb-f93c-49b6-89a0-1a211c4447fc"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Mobile Number:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="102" width="25" height="20" uuid="2981d3cf-d5f5-476b-b0db-9f76aa3be7e6"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
</box>
<textElement>
<font pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<staticText>
<reportElement x="0" y="0" width="555" height="10" uuid="0da2ed25-3390-41fb-b11c-4a7255b8ffc2"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<staticText>
<reportElement x="0" y="215" width="10" height="45" uuid="67f718dd-bc9f-45a1-9672-86ccb888b94f"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
</box>
<text><![CDATA[]]></text>
</staticText>
<image>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="10" width="139" height="92" isPrintWhenDetailOverflows="true" uuid="bc88f358-7651-47e5-9569-8860c0a0257a">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="false"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
</box>
<imageExpression><![CDATA[$F{companyLogo}.getBinaryStream()]]></imageExpression>
</image>
"all the extra cells like 'M','N','O' are to be removed?"
不能删除excel中的单元格(据我所知),您可以隐藏它们,但随后您会看到'P','Q','S' 因为这就是 excel 的开发方式。
"I want report to be center of the page" (interpreted as printed on center, otherwise again it depends only on the dimension of the excel window)
使用边距(简单的方法)
移除
exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
并根据需要设置页边距。
在打印中使用 excel 函数 >> 页边距:工作表在页面上水平居中
我没有在 jasper 报告中找到任何 属性 来实现这个,但是直接使用 POI 它相当简单(注意你已经在你的 class 路径中有了这个库,jasper报告使用它导出到 excel)
为此,您需要先导出报告 es。到一个文件(在服务器上)或者如果你有内存到 ByteArray
,这个例子假定你已经将它导出到你服务器上的 File excelFile
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(excelFile)); //create the workbook with POI
int ns = workbook.getNumberOfSheets();//Get the number of sheets (margins is set on sheet not on woorkbook
for (int i = 0; i < ns; i++) {
HSSFSheet sheet = workbook.getSheetAt(i); //Get the sheet
sheet.setHorizontallyCenter(true); //Set the property
//sheet.setMargin(Sheet.LeftMargin, 0.5);//You can also set margins ecc here margins are in Inches
}
workbook.write(outputStream); //write the excel to your stream
workbook.close(); //And close it
我已经使用 jasper 报告完成了一份报告并且得到了很好的报告,但我担心的是当我打开报告时它以 XLS 格式打开但它完全位于页面的左侧部分,如下所示
我希望报告位于页面的中心,所有多余的单元格,如 'M'、'N'、'O' 都将被删除。
Report.jsp
<body>
<%
String sql=null;
Connection conn = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/marketing_database","root","root");
sql = "select company_profile.companyName AS 'cname',quotationclient_details.RefNo,quotationclient_details.Date,quotationclient_details.CustomerName,quotationclient_details.CompanyName AS 'ccname',quotationclient_details.PaymentTerm,quotationclient_details.DeliveryTime,quotationclient_details.Validity,quotation.Item,quotation.id,quotation.Description,quotation.Quantity,quotation.PerUnitPrice,quotation.TotalPrice,quotation.VAT5,quotation.VAT14,quotation.CST,quotationclient_details.MobileNo,quotation.ServiceTax,company_profile.companyLogo,company_profile.companyLetterHead from quotation,quotationclient_details,company_profile where quotation.CId In (select max(CId) from quotationclient_details) and quotationclient_details.CId In (select max(CId) from quotationclient_details)";
ServletContext context = request.getServletContext();
String fullPath = context.getRealPath("/WEB-INF/reports/report9.jrxml");
InputStream input = new FileInputStream(new File(fullPath));
JasperDesign jasperDesign = JRXmlLoader.load(input);
System.out.println("Compiling Report Designs");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
System.out.println("Creating JasperPrint Object");
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("sql",sql);
JasperPrint jasperPrint = JasperFillManager.fillReport (jasperReport,map,conn);
byte bytes[] = new byte[10000];
//String result = JasperRunManager.runReportToHtmlFile("./usertemplates/test.jasper" , parameters, conn);
JRXlsExporter exporter = new JRXlsExporter();
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, xlsReport);
exporter.exportReport();
//System.out.println("Size of byte array:"+xlsReport.size());
//bytes = xlsReport.toByteArray();
String fileName = "QuotationReport.xls";
response.setHeader("Content-Disposition", "inline; filename="
+ fileName);
response.setContentType("application/vnd.ms-excel");
//System.out.println("After JasperPrint = 1");
response.setContentLength(xlsReport.size());
//System.out.println("After JasperPrint = 2");
//xlsReport.close();
//System.out.println("After JasperPrint = 3");
OutputStream outputStream = response.getOutputStream();
System.out.println("After JasperPrint = 4");
xlsReport.writeTo(outputStream);
outputStream.flush();
//outputStream.close();
}
catch(Exception e)
{e.printStackTrace();}
%>
</body>
report.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report11" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" scriptletClass="com.reporter.jasper.ConvertToWord" uuid="16229028-8f93-4195-966f-09e0c49feb94">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select
company_profile.companyName AS 'cname',
quotationclient_details.RefNo,
quotationclient_details.Date,
quotationclient_details.CustomerName,
quotationclient_details.CompanyName AS 'ccname',
quotationclient_details.PaymentTerm,
quotationclient_details.DeliveryTime,
quotationclient_details.Validity,
quotation.Item,quotation.id,
quotation.Description,
quotation.Quantity,
quotation.PerUnitPrice,
quotation.TotalPrice,
quotation.VAT5,
quotation.VAT14,
quotation.CST,
quotationclient_details.MobileNo,
quotation.ServiceTax,
company_profile.companyLogo,
company_profile.companyLetterHead
from quotation,quotationclient_details,company_profile where quotation.CId In (select max(CId) from quotationclient_details) and quotationclient_details.CId In (select max(CId) from quotationclient_details)]]>
</queryString>
<field name="cname" class="java.lang.String"/>
<field name="RefNo" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Date" class="java.sql.Date">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="CustomerName" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="ccname" class="java.lang.String"/>
<field name="PaymentTerm" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="DeliveryTime" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Validity" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Item" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="id" class="java.lang.Long">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Description" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="Quantity" class="java.lang.Long">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="PerUnitPrice" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="TotalPrice" class="java.lang.Double">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="VAT5" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="VAT14" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="CST" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="MobileNo" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="ServiceTax" class="java.lang.Float">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="companyLogo" class="java.sql.Blob">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="companyLetterHead" class="java.sql.Blob">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="Sub Total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{TotalPrice}]]></variableExpression>
</variable>
<variable name="Output VAT and CST and Service Tax" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{VAT5} +$F{VAT14} +$F{ServiceTax} +$F{CST}]]></variableExpression>
</variable>
<title>
<band height="260" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="25" y="102" width="268" height="20" uuid="f2e6a64d-e30b-4b5d-8ce0-8aa347bf4b24"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{RefNo}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="">
<reportElement x="293" y="102" width="262" height="20" uuid="3fbe0992-ece7-424f-b6e7-100482dcb771"/>
<box>
<topPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="313" y="122" width="242" height="14" isPrintWhenDetailOverflows="true" uuid="91ce3cf8-5ab5-45f1-97ac-92b88d453158"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{CustomerName}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="313" y="136" width="242" height="13" isPrintWhenDetailOverflows="true" uuid="8917fe3e-5ff5-492d-82c4-441701f82f7e"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{ccname}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="313" y="149" width="242" height="13" uuid="246061b8-09fd-4086-a735-146048a7a201"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement markup="none">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement x="313" y="175" width="242" height="20" uuid="c299b4ca-f46e-49ca-8d4f-b3204d06fc89"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement markup="none">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{MobileNo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="195" width="555" height="20" forecolor="#FF0000" uuid="cc2007f5-62a9-4b1c-a204-09566e931526"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="10" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Sub Quotation for supply of UPS and Batteries]]></text>
</staticText>
<staticText>
<reportElement x="10" y="215" width="545" height="45" uuid="3ae6bde4-be3c-40f0-8ac7-ac1274007b22"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Dear Sir,
We thank you for your enquiry and the interest shown in our range of products and services.As per the requirements provided by you,please find here below our revised offer in INR for the same]]></text>
</staticText>
<staticText>
<reportElement x="0" y="122" width="293" height="14" uuid="509840bf-7159-427d-93ff-e4cf88dc48aa"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<text><![CDATA[Contact Person Name:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="136" width="293" height="13" uuid="6a696a9c-830d-46de-9124-f1a5344c30d3"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" size="10" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Company Name:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="149" width="293" height="13" uuid="b9000080-e944-4e1f-a711-378e36c247b5"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Address:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="162" width="293" height="13" uuid="9f8b1f79-c8fd-4a65-9f93-4ce48440045b"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Email:]]></text>
</staticText>
<staticText>
<reportElement x="313" y="162" width="242" height="13" uuid="1eac5333-e70c-4afe-89bc-3fb39a8c9bef"/>
<box>
<rightPen lineWidth="0.5"/>
</box>
<textElement markup="none">
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<staticText>
<reportElement x="0" y="175" width="293" height="20" uuid="7ecaa5cb-f93c-49b6-89a0-1a211c4447fc"/>
<box>
<leftPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right">
<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Mobile Number:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="102" width="25" height="20" uuid="2981d3cf-d5f5-476b-b0db-9f76aa3be7e6"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
</box>
<textElement>
<font pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<staticText>
<reportElement x="0" y="0" width="555" height="10" uuid="0da2ed25-3390-41fb-b11c-4a7255b8ffc2"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<font pdfFontName="Times-Roman" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
<staticText>
<reportElement x="0" y="215" width="10" height="45" uuid="67f718dd-bc9f-45a1-9672-86ccb888b94f"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
</box>
<text><![CDATA[]]></text>
</staticText>
<image>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="10" width="139" height="92" isPrintWhenDetailOverflows="true" uuid="bc88f358-7651-47e5-9569-8860c0a0257a">
<property name="net.sf.jasperreports.export.xls.auto.fit.row" value="false"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
</reportElement>
<box>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
</box>
<imageExpression><![CDATA[$F{companyLogo}.getBinaryStream()]]></imageExpression>
</image>
"all the extra cells like 'M','N','O' are to be removed?"
不能删除excel中的单元格(据我所知),您可以隐藏它们,但随后您会看到'P','Q','S' 因为这就是 excel 的开发方式。
"I want report to be center of the page" (interpreted as printed on center, otherwise again it depends only on the dimension of the excel window)
使用边距(简单的方法)
移除
exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
并根据需要设置页边距。
在打印中使用 excel 函数 >> 页边距:工作表在页面上水平居中
我没有在 jasper 报告中找到任何 属性 来实现这个,但是直接使用 POI 它相当简单(注意你已经在你的 class 路径中有了这个库,jasper报告使用它导出到 excel)
为此,您需要先导出报告 es。到一个文件(在服务器上)或者如果你有内存到 ByteArray
,这个例子假定你已经将它导出到你服务器上的 File excelFile
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(excelFile)); //create the workbook with POI
int ns = workbook.getNumberOfSheets();//Get the number of sheets (margins is set on sheet not on woorkbook
for (int i = 0; i < ns; i++) {
HSSFSheet sheet = workbook.getSheetAt(i); //Get the sheet
sheet.setHorizontallyCenter(true); //Set the property
//sheet.setMargin(Sheet.LeftMargin, 0.5);//You can also set margins ecc here margins are in Inches
}
workbook.write(outputStream); //write the excel to your stream
workbook.close(); //And close it