Example usage for org.apache.poi.hssf.usermodel HSSFCellStyle setFont

List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setFont

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCellStyle setFont.

Prototype

public void setFont(HSSFFont font) 

Source Link

Usage

From source file:excel.FileExcel.java

public File excel_create_kirim_barang(ArrayList<ItemReadyData> ItemsReadyData, Date currentdate) {
    if (ItemsReadyData.size() != 0) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "Kirim_" + fmt.format(currentdate) + "_" + time.format(currentdate) + "_konter_"
                + ItemsReadyData.get(0).kode_konter + ".xls";
        File ExcelKirimBarang = new File(fileName);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        // set page
        sheet.getPrintSetup().setLandscape(true);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);/*from   w ww .  j  av  a  2  s.c o  m*/

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL KIRIM BARANG");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 9));

        // create file info
        // create file info
        header = sheet.createRow(3);
        cell = header.createCell(2);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(3);
        cell.setCellValue(fmt.format(currentdate));

        header = sheet.createRow(4);
        cell = header.createCell(2);
        cell.setCellValue("Konter : ");
        cell = header.createCell(3);
        cell.setCellValue(ItemsReadyData.get(0).kode_konter);

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Barang");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Jumlah");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Nama Barang");
        cell = header.createCell(4);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kategori");
        cell = header.createCell(5);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga TPG");
        cell = header.createCell(6);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Discount");
        cell = header.createCell(7);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga Net");
        cell = header.createCell(8);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total TPG");
        cell = header.createCell(9);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total Net");

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        HSSFDataFormat df = workbook.createDataFormat();
        datastyle.setDataFormat(df.getFormat("#,###"));
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        double net = 0;
        double total_tpg = 0;
        double total_net = 0;
        double sum_total_tpg = 0;
        double sum_total_net = 0;
        int j;

        // fill the data
        for (j = 0; j < ItemsReadyData.size(); j++) {
            net = (double) ItemsReadyData.get(j).harga_tpg
                    * (100.0 - (double) ItemsReadyData.get(j).disc_member) / 100.0;
            total_tpg = (double) ItemsReadyData.get(j).harga_tpg * (double) ItemsReadyData.get(j).jumlah_barang;
            total_net = (double) net * (double) ItemsReadyData.get(j).jumlah_barang;
            sum_total_tpg += total_tpg;
            sum_total_net += total_net;

            header = sheet.createRow(8 + j);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).kode_barang);
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).jumlah_barang);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).nama_barang);
            cell = header.createCell(4);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).kategori);
            cell = header.createCell(5);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).harga_tpg);
            cell = header.createCell(6);
            cell.setCellStyle(datastyle);
            cell.setCellValue(ItemsReadyData.get(j).disc_member);
            cell = header.createCell(7);
            cell.setCellStyle(datastyle);
            cell.setCellValue(net);
            cell = header.createCell(8);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_tpg);
            cell = header.createCell(9);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_net);
        }

        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);
        sheet.autoSizeColumn(4);
        sheet.autoSizeColumn(5);
        sheet.autoSizeColumn(6);
        sheet.autoSizeColumn(7);
        sheet.autoSizeColumn(8);
        sheet.autoSizeColumn(9);

        datastyle.setFont(boldfont);
        header = sheet.createRow(j + 8);
        cell = header.createCell(7);
        cell.setCellStyle(datastyle);
        cell.setCellValue("TOTAL");
        cell = header.createCell(8);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_tpg);
        cell = header.createCell(9);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_net);

        try {
            FileOutputStream out = new FileOutputStream(ExcelKirimBarang);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            ExcelKirimBarang = null;
        } catch (IOException e) {
            e.printStackTrace();
            ExcelKirimBarang = null;
        }
        return ExcelKirimBarang;
    } else {
        return null;
    }
}

From source file:excel.FileExcel.java

public File excel_create_cari_gudang(ArrayList<CariGudangReportData> CariGudang, Date waktuprint) {
    // find number of counter, save in Counter Index
    if (!CariGudang.isEmpty()) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "CariGudang_" + fmt.format(waktuprint) + "_" + time.format(waktuprint) + ".xls";
        File FileCariGudang = new File(fileName);

        HSSFWorkbook workbook;/*  w  w  w  .  j  av a2s  .c  o m*/
        HSSFSheet sheet;

        workbook = new HSSFWorkbook();
        sheet = workbook.createSheet();

        // set page
        HSSFPrintSetup ps = sheet.getPrintSetup();
        ps.setLandscape(true);
        ps.setFitHeight((short) 1);
        ps.setFitWidth((short) 1);
        sheet.setFitToPage(true);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL CARI GUDANG");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 4));

        // create file info
        header = sheet.createRow(4);
        cell = header.createCell(1);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(2);
        cell.setCellValue(fmt.format(waktuprint));

        header = sheet.createRow(5);
        cell = header.createCell(1);
        cell.setCellValue("Jam : ");
        cell = header.createCell(2);
        cell.setCellValue(time.format(waktuprint));

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Order");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Konter");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Barang");
        cell = header.createCell(4);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Jumlah");
        cell = header.createCell(5);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Nama Barang");
        cell = header.createCell(6);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kategori");
        cell = header.createCell(7);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("HargaTPG");
        cell = header.createCell(8);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Disc");
        cell = header.createCell(9);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga Net");
        cell = header.createCell(10);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total Net");

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        HSSFDataFormat df = workbook.createDataFormat();
        datastyle.setDataFormat(df.getFormat("#,###"));
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        int row_num = 0;

        double net = 0;
        double total_tpg = 0;
        double total_net = 0;
        double sum_total_tpg = 0;
        double sum_total_net = 0;

        int j;
        for (j = 0; j < CariGudang.size(); j++) {
            net = (double) CariGudang.get(j).harga_tpg * (100.0 - (double) CariGudang.get(j).disc) / 100.0;
            total_net = (double) net * (double) CariGudang.get(j).jumlah;
            sum_total_tpg += total_tpg;
            sum_total_net += total_net;

            header = sheet.createRow(8 + row_num);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kode_order);
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kode_konter);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kode_barang);
            cell = header.createCell(4);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).jumlah);
            cell = header.createCell(5);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).nama_barang);
            cell = header.createCell(6);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).kategori);
            cell = header.createCell(7);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).harga_tpg);
            cell = header.createCell(8);
            cell.setCellStyle(datastyle);
            cell.setCellValue(CariGudang.get(j).disc);
            cell = header.createCell(9);
            cell.setCellStyle(datastyle);
            cell.setCellValue(net);
            cell = header.createCell(10);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_net);
            row_num++;
        }

        datastyle.setFont(boldfont);
        header = sheet.createRow(j + 8);
        cell = header.createCell(9);
        cell.setCellStyle(datastyle);
        cell.setCellValue("TOTAL");
        cell = header.createCell(10);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_net);

        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);
        sheet.autoSizeColumn(4);
        sheet.autoSizeColumn(5);
        sheet.autoSizeColumn(6);
        sheet.autoSizeColumn(7);
        sheet.autoSizeColumn(8);
        sheet.autoSizeColumn(9);
        sheet.autoSizeColumn(10);

        try {
            FileOutputStream out = new FileOutputStream(FileCariGudang);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            FileCariGudang = null;
        } catch (IOException e) {
            e.printStackTrace();
            FileCariGudang = null;
        }
        return FileCariGudang;
    } else {
        return null;
    }
}

From source file:excel.FileExcel.java

public File excel_create_dead_style(ArrayList<DeadStyleData> DSData, Date currentdate, int discDS) {
    if (DSData.size() != 0) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "DeadStyle_" + fmt.format(currentdate) + "_" + time.format(currentdate) + ".xls";
        File ExcelDeadStyle = new File(fileName);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        // set page
        sheet.getPrintSetup().setLandscape(false);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);/*from  w  w w .  ja v a  2 s  .  co m*/

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL DEAD STYLE");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 9));

        // create file info
        // create file info
        header = sheet.createRow(3);
        cell = header.createCell(2);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(3);
        cell.setCellValue(fmt.format(currentdate));

        header = sheet.createRow(4);
        cell = header.createCell(2);
        cell.setCellValue("Jam : ");
        cell = header.createCell(3);
        cell.setCellValue(time.format(currentdate));

        header = sheet.createRow(5);
        cell = header.createCell(2);
        cell.setCellValue("Diskon : ");
        cell = header.createCell(3);
        cell.setCellValue(discDS);

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kode Barang");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Nama Barang");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Jumlah");
        cell = header.createCell(4);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Kategori");
        cell = header.createCell(5);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga TPG");
        cell = header.createCell(6);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Discount");
        cell = header.createCell(7);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Harga Net");
        cell = header.createCell(8);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total TPG");
        cell = header.createCell(9);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Total Net");
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);
        sheet.autoSizeColumn(4);
        sheet.autoSizeColumn(5);
        sheet.autoSizeColumn(6);
        sheet.autoSizeColumn(7);
        sheet.autoSizeColumn(8);
        sheet.autoSizeColumn(9);

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        double net = 0;
        double total_tpg = 0;
        double total_net = 0;
        double sum_total_tpg = 0;
        double sum_total_net = 0;
        int j;
        double dsdisc;

        // fill the data
        for (j = 0; j < DSData.size(); j++) {
            dsdisc = (DSData.get(j).disc_member == 10) ? 0 : discDS;
            net = (double) DSData.get(j).harga_tpg * (100.0 - dsdisc) / 100.0;
            total_tpg = (double) DSData.get(j).harga_tpg * (double) DSData.get(j).Jumlah;
            total_net = (double) net * (double) DSData.get(j).Jumlah;
            sum_total_tpg += total_tpg;
            sum_total_net += total_net;

            header = sheet.createRow(8 + j);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(DSData.get(j).kode_barang);
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(DSData.get(j).nama_barang);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(DSData.get(j).Jumlah);
            cell = header.createCell(4);
            cell.setCellStyle(datastyle);
            cell.setCellValue(DSData.get(j).kategori);
            cell = header.createCell(5);
            cell.setCellStyle(datastyle);
            cell.setCellValue(DSData.get(j).harga_tpg);
            cell = header.createCell(6);
            cell.setCellStyle(datastyle);
            cell.setCellValue(DSData.get(j).disc_member);
            cell = header.createCell(7);
            cell.setCellStyle(datastyle);
            cell.setCellValue(net);
            cell = header.createCell(8);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_tpg);
            cell = header.createCell(9);
            cell.setCellStyle(datastyle);
            cell.setCellValue(total_net);
        }

        datastyle.setFont(boldfont);
        header = sheet.createRow(j + 8);
        cell = header.createCell(7);
        cell.setCellStyle(datastyle);
        cell.setCellValue("TOTAL");
        cell = header.createCell(8);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_tpg);
        cell = header.createCell(9);
        cell.setCellStyle(datastyle);
        cell.setCellValue(sum_total_net);

        try {
            FileOutputStream out = new FileOutputStream(ExcelDeadStyle);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            ExcelDeadStyle = null;
        } catch (IOException e) {
            e.printStackTrace();
            ExcelDeadStyle = null;
        }
        return ExcelDeadStyle;
    } else {
        return null;
    }
}

From source file:excel.FileExcel.java

public File excel_mutation_report(ArrayList<MutationReportData> datamutation, KodeNamaKonter konterinfo,
        Date Start, Date End, Date CurrentDate) {
    if (datamutation.size() != 0) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "Mutation_" + konterinfo.nama_konter + "_" + fmt.format(CurrentDate) + "_"
                + time.format(CurrentDate) + ".xls";
        File ExcelMutation = new File(fileName);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        // set page
        sheet.getPrintSetup().setLandscape(false);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);/*  w w  w .j a v  a2s  .c  om*/

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL MUTATION REPORT");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 3));

        // create file info
        // create file info
        header = sheet.createRow(3);
        cell = header.createCell(2);
        cell.setCellValue("Konter : ");
        cell = header.createCell(3);
        cell.setCellValue(konterinfo.nama_konter);

        header = sheet.createRow(4);
        cell = header.createCell(2);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(3);
        cell.setCellValue(fmt.format(Start));
        cell = header.createCell(4);
        cell.setCellValue("-");
        cell = header.createCell(5);
        cell.setCellValue(fmt.format(End));

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Tanggal");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Barang Masuk");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Setoran Masuk");
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        int i;
        // fill the data
        for (i = 0; i < datamutation.size(); i++) {
            header = sheet.createRow(8 + i);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(fmt.format(datamutation.get(i).tanggal_mutasi));
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(datamutation.get(i).barang_keluar);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(datamutation.get(i).setoran);
        }

        datastyle.setFont(boldfont);
        header = sheet.createRow(i + 10);
        cell = header.createCell(1);
        cell.setCellStyle(datastyle);
        cell.setCellValue("Hutang Konter");
        cell = header.createCell(2);
        cell.setCellStyle(datastyle);
        cell.setCellValue(fmt.format(CurrentDate));
        cell = header.createCell(3);
        cell.setCellStyle(datastyle);
        cell.setCellValue(konterinfo.hutang_konter);
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);

        try {
            FileOutputStream out = new FileOutputStream(ExcelMutation);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            ExcelMutation = null;
        } catch (IOException e) {
            e.printStackTrace();
            ExcelMutation = null;
        }
        return ExcelMutation;
    } else {
        return null;
    }
}

From source file:Excel.InformeArticulos.java

public void GenerarInforme(ArrayList listadoClientes) throws SQLException {
    HSSFWorkbook libro = new HSSFWorkbook();
    HSSFSheet hoja = libro.createSheet("Listado de Articulos");
    ArrayList listadoPorSucursal = new ArrayList();
    Editables edi = new Articulos();

    /*//from   w  w  w. j  a  v a  2 s.  co m
     * GENERAR LAS SIGUIENTES HOJAS
     * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y 
     * NUMERO DE CAJA
     * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA
     * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS
     * 
     */

    String ttx = "celda numero :";
    HSSFRow fila = null;
    HSSFCell celda;
    HSSFCell celda1;
    HSSFCell celda2;
    HSSFCell celda3;
    HSSFCell celda4;
    HSSFCell celda5;
    HSSFCell celda6;
    HSSFCell celda7;
    HSSFCell celda8;
    HSSFCell celda9;
    HSSFCell celda10;
    HSSFCell celda11;
    HSSFFont fuente = libro.createFont();
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    String form = null;

    HSSFCellStyle titulo = libro.createCellStyle();
    Iterator iCli = listadoClientes.listIterator();
    Articulos cliente = new Articulos();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    int col = 0;
    int a = 0;
    if (a == 0) {
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Codigo");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Descripcion");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Stock");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Stock Mnimo");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Costo");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("Precio de Venta");
        celda6 = fila.createCell(6);
        celda6.setCellStyle(titulo);
        celda6.setCellValue("Servicio");
    }
    while (iCli.hasNext()) {
        cliente = (Articulos) iCli.next();
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;

        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(cliente.getCodigoAsignado());
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(cliente.getDescripcionArticulo());
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda2.setCellValue(cliente.getStockActual());
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda3.setCellValue(cliente.getStockMinimo());
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(cliente.getPrecioDeCosto());

        celda5 = fila.createCell(5);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda5.setCellValue(cliente.getPrecioUnitarioNeto());
        //celda5.setCellValue(rs.getDate("fecha"));
        celda6 = fila.createCell(6);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda6.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda6.setCellValue(cliente.getPrecioServicio());
        listadoPorSucursal = edi.ListarPorSucursal(cliente);
        Iterator il = listadoPorSucursal.listIterator();
        Articulos arr = new Articulos();
        int cont = 0;
        while (il.hasNext()) {
            arr = (Articulos) il.next();
            cont++;
            switch (cont) {

            case 1:
                celda7 = fila.createCell(7);
                celda7.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                celda7.setCellValue(arr.getCantidad());
                break;
            case 2:
                celda8 = fila.createCell(8);
                celda8.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                celda8.setCellValue(arr.getCantidad());
                break;
            case 3:
                celda9 = fila.createCell(9);
                celda9.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                celda9.setCellValue(arr.getCantidad());
                break;
            case 4:
                celda10 = fila.createCell(10);
                celda10.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                celda10.setCellValue(arr.getCantidad());
                break;
            }

        }
    }

    //texto+="\r\n";
    String ruta = "C://Informes//listadoDeArticulos.xls";
    try {
        FileOutputStream elFichero = new FileOutputStream(ruta);
        try {
            libro.write(elFichero);
            elFichero.close();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta);
        } catch (IOException ex) {
            Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Excel.InformeDiarioStock.java

public void GenerrarInformeStock() throws SQLException {
    HSSFWorkbook libro = new HSSFWorkbook();
    HSSFSheet hoja = libro.createSheet("Articulos");
    /*/*from w w w  .  jav a2  s .  c  om*/
     * GENERAR LAS SIGUIENTES HOJAS
     * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y 
     * NUMERO DE CAJA
     * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA
     * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS
     * 
     */
    HSSFSheet hoja1 = libro.createSheet("Movimientos");
    HSSFSheet hoja2 = libro.createSheet("Movimientos Caja");

    String ttx = "celda numero :";
    HSSFRow fila = null;
    HSSFCell celda;
    HSSFCell celda1;
    HSSFCell celda2;
    HSSFCell celda3;
    HSSFCell celda4;
    HSSFCell celda5;
    HSSFCell celda6;
    HSSFCell celda7;
    HSSFCell celda8;
    HSSFCell celda9;
    HSSFCell celda10;
    HSSFFont fuente = libro.createFont();
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    String form = null;
    //String sql="select id,nombre,(select sum(movimientosarticulos.cantidad) from movimientosarticulos where movimientosarticulos.idarticulo=articulos.id and movimientosarticulos.numerodeposito="+Inicio.deposito.getNumero()+")as stock,(select sum(movimientosarticulos.cantidad) from movimientosarticulos where movimientosarticulos.idcaja="+Inicio.caja.getNumero()+" and movimientosarticulos.idarticulo=articulos.id)as cantidadVendida from articulos";
    String sql = "select *,(select articulos.NOMBRE from articulos where articulos.ID=movimientosarticulos.idArticulo)as descripcion from movimientosarticulos where idcaja="
            + Inicio.caja.getNumero();
    System.out.println(sql);
    Transaccionable tra = new ConeccionLocal();
    ResultSet rs = tra.leerConjuntoDeRegistros(sql);
    HSSFCellStyle titulo = libro.createCellStyle();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    int col = 0;
    int a = 0;
    if (a == 0) {
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("id");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("nombre");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Unidades Vendidas");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Fecha");
    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;
        Double anterior = 0.00;
        Double actual = 0.00;
        Double vendido = 0.00;
        celda.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda.setCellValue(rs.getInt("idArticulo"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(rs.getString("descripcion"));
        celda2 = fila.createCell(2);
        vendido = (rs.getDouble("cantidad")) * -1;
        //actual=rs.getDouble("stock");
        celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda2.setCellValue(vendido);
        celda3 = fila.createCell(3);
        //vendido=(rs.getDouble("cantidadVendida")) * -1;
        celda3.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda3.setCellValue(rs.getString("fecha"));

    }
    //rs.close();

    // hoja 2

    form = null;
    sql = "SELECT id,cantidad,preciodecosto,preciodeventa,precioservicio,fecha,numerocomprobante,(select listcli.RAZON_SOCI from listcli where listcli.codMmd=movimientosarticulos.numeroCliente limit 0,1)as nombreC,(select articulos.NOMBRE from articulos where articulos.ID=movimientosarticulos.idArticulo limit 0,1)as descA,(select usuarios.nombre from usuarios where usuarios.numero=movimientosarticulos.numeroUsuario limit 0,1) as nombreU FROM movimientosarticulos where tipoMovimiento =1 and idcaja="
            + Inicio.caja.getNumero();
    //System.out.println(sql);
    //tra=new Conecciones();
    rs = tra.leerConjuntoDeRegistros(sql);
    //HSSFCellStyle titulo=libro.createCellStyle();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    col = 0;
    a = 0;
    if (a == 0) {
        fila = hoja1.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Cajero");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Descripcion Articulo");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Cantidad");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Precio de Costo");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Precio de Venta");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("Fecha");
        celda6 = fila.createCell(6);
        celda6.setCellStyle(titulo);
        celda6.setCellValue("Precio de Servicio");
        celda7 = fila.createCell(7);
        celda7.setCellStyle(titulo);
        celda7.setCellValue("comprobante");

        celda8 = fila.createCell(8);
        celda8.setCellStyle(titulo);
        celda8.setCellValue("Cliente");
        celda9 = fila.createCell(9);
        celda9.setCellStyle(titulo);
        celda9.setCellValue("Total");
        celda10 = fila.createCell(10);
        celda10.setCellStyle(titulo);
        celda10.setCellValue("idMovimiento");

    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja1.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;
        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(rs.getString("nombreU"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(rs.getString("descA"));
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda2.setCellValue(rs.getDouble("cantidad"));
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda3.setCellValue(rs.getDouble("precioDeCosto"));
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(rs.getDouble("precioDeVenta"));

        celda5 = fila.createCell(5);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda5.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda5.setCellValue(" " + rs.getDate("fecha"));
        //celda5.setCellValue(rs.getDate("fecha"));
        celda6 = fila.createCell(6);
        celda6.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda6.setCellValue(rs.getDouble("precioServicio"));
        celda7 = fila.createCell(7);
        celda7.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda7.setCellValue(rs.getInt("numeroComprobante"));

        celda8 = fila.createCell(8);
        celda8.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda8.setCellValue(rs.getString("nombreC"));

        celda9 = fila.createCell(9);
        celda9.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        Double tto = 0.00;
        tto = rs.getDouble("precioServicio") + rs.getDouble("precioDeVenta");
        celda9.setCellValue(tto);
        celda10 = fila.createCell(10);
        celda10.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda10.setCellValue(rs.getInt("id"));
    }

    form = null;
    sql = "SELECT *,(select usuarios.nombre from usuarios where usuarios.numero=movimientoscaja.numeroUsuario)as nombreUsuario,(select listcli.RAZON_SOCI from listcli where listcli.id=movimientoscaja.idCliente)as nombreCliente,(select tipocomprobantes.descripcion from tipocomprobantes where tipocomprobantes.numero=movimientoscaja.tipoComprobante)as nombreComprobante,(select tipomovimientos.DESCRIPCION from tipomovimientos where tipomovimientos.ID=movimientoscaja.tipoMovimiento)as nombreMov FROM movimientoscaja where idcaja="
            + Inicio.caja.getNumero() + " order by id";
    //System.out.println(sql);
    //tra=new Conecciones();
    rs = tra.leerConjuntoDeRegistros(sql);
    //HSSFCellStyle titulo=libro.createCellStyle();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    col = 0;
    a = 0;
    if (a == 0) {
        fila = hoja2.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Cajero");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Cliente");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Comprobante Numero");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Tipo Comprobante");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Monto");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("Fecha");
        celda6 = fila.createCell(6);
        celda6.setCellStyle(titulo);
        celda6.setCellValue("Tipo de Movimiento");
        celda7 = fila.createCell(7);
        celda7.setCellStyle(titulo);
        celda7.setCellValue("Condicion");

        celda8 = fila.createCell(8);
        celda8.setCellStyle(titulo);
        celda8.setCellValue("idMovimiento");

    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja2.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;
        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(rs.getString("nombreUsuario"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(rs.getString("nombreCliente"));
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda2.setCellValue(rs.getInt("numeroComprobante"));
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda3.setCellValue(rs.getString("nombreComprobante"));
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(rs.getDouble("monto"));

        celda5 = fila.createCell(5);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda5.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda5.setCellValue(" " + rs.getDate("fecha"));
        //celda5.setCellValue(rs.getDate("fecha"));
        celda6 = fila.createCell(6);
        celda6.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda6.setCellValue(rs.getString("nombreMov"));
        celda7 = fila.createCell(7);
        String pagado = "PAGADO";
        if (rs.getInt("pagado") == 0 && rs.getInt("tipoMovimiento") == 1)
            pagado = "CTA CTE";
        celda7.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda7.setCellValue(pagado);

        celda8 = fila.createCell(8);
        celda8.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda8.setCellValue(rs.getInt("id"));
    }

    rs.close();

    //texto+="\r\n";
    String ruta = "C://Informes//" + Inicio.fechaDia + "_" + Inicio.usuario.getNombre()
            + " - informeDeStock.xls";
    String nombree = Inicio.fechaDia + "_" + Inicio.usuario.getNombre() + " - informeDeStock.xls";
    try {
        FileOutputStream elFichero = new FileOutputStream(ruta);
        try {
            libro.write(elFichero);
            elFichero.close();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta);
            Mail mail = new Mail();
            String mailRecepcion = Propiedades.getCORREOCIERREDECAJA();
            mail.setDetalleListado(nombree);
            mail.setDireccionFile(ruta);
            mail.setAsunto("Informe de cierre de caja " + Inicio.fechaDia + " Sucursal: "
                    + Propiedades.getNOMBRECOMERCIO());
            mail.enviarMailRepartoCargaCompleta(mailRecepcion);
        } catch (IOException ex) {
            Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MessagingException ex) {
            Logger.getLogger(InformeDiarioStock.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "NO SE HA PODIDO ENVIAR EL MENSAJE MOTIVO :" + ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
    }
    sql = "select id,nombre,precio,servicio,(select sum(movimientosarticulos.cantidad) from movimientosarticulos where movimientosarticulos.idcaja="
            + Inicio.caja.getNumero()
            + " and movimientosarticulos.idarticulo=articulos.id)as cantidadVendida from articulos order by cantidadVendida desc";
    rs = tra.leerConjuntoDeRegistros(sql);
    System.out.println(sql);
    Transaccionable tt = new Conecciones();
    String sql1;
    Double cantVend;
    while (rs.next()) {
        cantVend = rs.getDouble("cantidadVendida");
        if (cantVend < 0) {
            //sql1="insert into movimientosarticulosF (tipoMovimiento,idArticulo,cantidad,numeroDeposito,tipoComprobante,numeroCliente,numerousuario,precioDeVenta,precioServicio,idcaja) values (1,"+rs.getInt("id")+",floor("+rs.getDouble("cantidadVendida")+" * 0.1),"+Inicio.deposito.getNumero()+",1,1,"+Inicio.usuario.getNumeroId()+","+rs.getDouble("precio")+","+rs.getDouble("servicio")+","+Inicio.caja.getNumero()+")";
            //System.out.println(sql1);
            //tt.guardarRegistro(sql1);
        }

    }
}

From source file:Excel.InformesClientes.java

public void GenerarInforme(ArrayList listadoClientes, String desde, String hasta) throws SQLException {
    HSSFWorkbook libro = new HSSFWorkbook();
    HSSFSheet hoja = libro.createSheet("Saldos de Clientes");
    HSSFSheet hoja1 = libro.createSheet("Detalle de Saldos");

    /*/*from   w  w w  .  jav  a 2s . c om*/
     * GENERAR LAS SIGUIENTES HOJAS
     * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y 
     * NUMERO DE CAJA
     * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA
     * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS
     * 
     */

    String ttx = "celda numero :";
    HSSFRow fila = null;
    HSSFCell celda;
    HSSFCell celda1;
    HSSFCell celda2;
    HSSFCell celda3;
    HSSFCell celda4;
    HSSFCell celda5;
    HSSFCell celda6;
    HSSFCell celda7;
    HSSFCell celda8;
    HSSFFont fuente = libro.createFont();
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    String form = null;
    String sql = "";
    System.out.println(sql);
    Transaccionable tra = new Conecciones();
    ResultSet rs = null;
    HSSFCellStyle titulo = libro.createCellStyle();
    Iterator iCli = listadoClientes.listIterator();
    ClientesTango cliente = new ClientesTango();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    int col = 0;
    int a = 0;
    if (a == 0) {
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Cod. Cliente");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Nombre");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Direccion");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Telfono");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Cupo de Crdito");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("Saldo");
    }
    while (iCli.hasNext()) {
        cliente = (ClientesTango) iCli.next();
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;
        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(cliente.getCodigoCliente());
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(cliente.getRazonSocial());
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda2.setCellValue(cliente.getDireccion());
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda3.setCellValue(cliente.getTelefono());
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(cliente.getCupoDeCredito());

        celda5 = fila.createCell(5);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        if (cliente.getSaldo() != null) {
            celda5.setCellValue(cliente.getSaldo());
        } else {
            celda5.setCellValue(0.00);
        }
        //celda5.setCellValue(rs.getDate("fecha"));

    }
    /*
     * segunda hoja
     */
    Busquedas bus = new ClientesTango();
    sql = "select numeroProveedor,fecha,monto,numeroComprobante,idUsuario,idCaja,(select tipomovimientos.descripcion from tipomovimientos where tipomovimientos.ID=movimientosclientes.tipoComprobante)as tipocomprobante1,idSucursal,(select listcli.razon_soci from listcli where listcli.codmmd=numeroProveedor)as nombreP from movimientosclientes where numeroProveedor > 1 and fecha between '"
            + desde + "' and '" + hasta
            + "' group by numeroComprobante,tipoComprobante order by numeroProveedor,fecha";
    System.out.println(sql);
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    form = null;
    //String sql="SELECT *,(select proveedores.nombre from proveedores where proveedores.numero=movimientosproveedores.numeroProveedor)as nombreP,if(pagado=0,'pendiente','pagado')as estado FROM movimientosproveedores where fecha between '"+desde+"' and '"+hasta+"'";
    //System.out.println(sql);
    //tra=new Conecciones();
    rs = tra.leerConjuntoDeRegistros(sql);
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    col = 0;
    a = 0;
    if (a == 0) {
        fila = hoja1.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Cliente");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Sucursal");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Fecha");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Monto");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Caja Numero");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("tipo de comprobante");
    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja1.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;

        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(rs.getString("nombreP"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda1.setCellValue(rs.getInt("idSucursal"));
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda2.setCellValue(" " + rs.getString("fecha"));
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda3.setCellValue(rs.getDouble("monto"));
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(rs.getInt("idCaja"));
        celda5 = fila.createCell(5);
        celda5.setCellType(HSSFCell.CELL_TYPE_STRING);
        //if(rs.getInt("tipoComprobante")==11){
        //celda5.setCellValue("Recibo de Pago");
        //}else{
        celda5.setCellValue(rs.getString("tipocomprobante1"));
        //}
    }

    rs.close();
    //texto+="\r\n";
    String ruta = "C://Informes//" + desde + "_" + hasta + "_informeDeClientes.xls";
    try {
        FileOutputStream elFichero = new FileOutputStream(ruta);
        try {
            libro.write(elFichero);
            elFichero.close();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta);
        } catch (IOException ex) {
            Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Excel.InformesClientes.java

public void GenerarInformeIndividual(ClientesTango idCliente) throws SQLException {
    HSSFWorkbook libro = new HSSFWorkbook();
    HSSFSheet hoja1 = libro.createSheet("Detalle de Saldos");
    //HSSFSheet hoja1=libro.createSheet("Detalle de Saldos");

    /*/*  w  w w .  j a  va 2 s .c  o m*/
     * GENERAR LAS SIGUIENTES HOJAS
     * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y 
     * NUMERO DE CAJA
     * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA
     * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS
     * 
     */

    String ttx = "celda numero :";
    HSSFRow fila = null;
    HSSFCell celda;
    HSSFCell celda1;
    HSSFCell celda2;
    HSSFCell celda3;
    HSSFCell celda4;
    HSSFCell celda5;
    HSSFCell celda6;
    HSSFCell celda7;
    HSSFCell celda8;
    HSSFFont fuente = libro.createFont();
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    String form = null;
    String sql = "";
    System.out.println(sql);
    Transaccionable tra = new Conecciones();
    ResultSet rs = null;
    HSSFCellStyle titulo = libro.createCellStyle();
    //Iterator iCli=listadoClientes.listIterator();
    ClientesTango cliente = new ClientesTango();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    int col = 0;
    int a = 0;
    /*
     * segunda hoja
     */
    //Facturar bus=new ClientesTango();
    cliente = idCliente;
    sql = "select numeroProveedor,fecha,monto,numeroComprobante,idUsuario,idCaja,(select tipomovimientos.descripcion from tipomovimientos where tipomovimientos.ID=movimientosclientes.tipoComprobante)as tipocomprobante1,idSucursal,(select listcli.razon_soci from listcli where listcli.codmmd=numeroProveedor)as nombreP from movimientosclientes where numeroProveedor="
            + cliente.getCodigoId() + " group by numeroComprobante,tipoComprobante order by fecha desc";
    System.out.println(sql);
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    form = null;
    //String sql="SELECT *,(select proveedores.nombre from proveedores where proveedores.numero=movimientosproveedores.numeroProveedor)as nombreP,if(pagado=0,'pendiente','pagado')as estado FROM movimientosproveedores where fecha between '"+desde+"' and '"+hasta+"'";
    //System.out.println(sql);
    //tra=new Conecciones();
    rs = tra.leerConjuntoDeRegistros(sql);
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    col = 0;
    a = 0;
    if (a == 0) {
        fila = hoja1.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Cliente");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Sucursal");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Fecha");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Monto");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Caja Numero");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("tipo de comprobante");
    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja1.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;

        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(rs.getString("nombreP"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda1.setCellValue(rs.getInt("idSucursal"));
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda2.setCellValue(" " + rs.getString("fecha"));
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda3.setCellValue(rs.getDouble("monto"));
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(rs.getInt("idCaja"));
        celda5 = fila.createCell(5);
        celda5.setCellType(HSSFCell.CELL_TYPE_STRING);
        //if(rs.getInt("tipoComprobante")==11){
        //celda5.setCellValue("Recibo de Pago");
        //}else{
        celda5.setCellValue(rs.getString("tipocomprobante1"));
        //}
    }

    rs.close();
    //texto+="\r\n";
    String clie = cliente.getRazonSocial().replaceAll(" ", "_");
    String ruta = "Informes\\" + clie + "_informeDetalleDeSaldo.xls";
    try {
        FileOutputStream elFichero;
        elFichero = new FileOutputStream(ruta);
        try {
            libro.write(elFichero);
            elFichero.close();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta);
        } catch (IOException ex) {
            Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Excel.Informesfacturables.java

public void GenerarInforme(String desde, String hasta) throws SQLException, IOException {
    HSSFWorkbook libro = new HSSFWorkbook();
    HSSFSheet hoja = libro.createSheet("Resumen");
    /*//from   ww w . jav a 2  s.  c  o  m
     * GENERAR LAS SIGUIENTES HOJAS
     * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y 
     * NUMERO DE CAJA
     * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA
     * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS
     * 
     */

    String ttx = "celda numero :";
    HSSFRow fila = null;
    HSSFCell celda;
    HSSFCell celda1;
    HSSFCell celda2;
    HSSFCell celda3;
    HSSFCell celda4;
    HSSFCell celda5;
    HSSFCell celda6;
    HSSFCell celda7;
    HSSFCell celda8;
    HSSFFont fuente = libro.createFont();
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    String form = null;
    String sql = "SELECT *,(select articulos.NOMBRE from articulos where articulos.ID=movimientosarticulosF.idArticulo)as descA,(select depositos.descripcion from depositos where depositos.numero=movimientosarticulosF.numeroDeposito)as depor  FROM movimientosarticulosF WHERE idArticulo > 1 and fecha between '"
            + desde + "' and '" + hasta + "'";
    System.out.println(sql);
    Transaccionable tra = new Conecciones();
    ResultSet rs = tra.leerConjuntoDeRegistros(sql);
    HSSFCellStyle titulo = libro.createCellStyle();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    int col = 0;
    int a = 0;
    Integer cantidad = 0;
    Double total = 0.00;
    if (a == 0) {
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Fecha");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Codigo");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Articulo");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Cantidad");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Precio Unitario");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("Total");
        celda6 = fila.createCell(6);
        celda6.setCellStyle(titulo);
        celda6.setCellValue("idCaja");
        celda7 = fila.createCell(7);
        celda7.setCellStyle(titulo);
        celda7.setCellValue("Sucursal");
    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;
        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(rs.getString("fecha"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(rs.getString("idArticulo"));
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda2.setCellValue(rs.getString("descA"));
        celda3 = fila.createCell(3);
        cantidad = 0;
        total = 0.00;
        cantidad = rs.getInt("cantidad") * -1;
        total = rs.getDouble("precioDeVenta") * cantidad;
        celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda3.setCellValue(cantidad);
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(rs.getDouble("precioDeVenta"));

        celda5 = fila.createCell(5);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda5.setCellValue(total);
        //celda5.setCellValue(rs.getDate("fecha"));
        celda6 = fila.createCell(6);
        celda6.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda6.setCellValue(rs.getInt("idcaja"));
        celda7 = fila.createCell(7);
        celda7.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda7.setCellValue(rs.getString("depor"));
    }

    rs.close();
    //texto+="\r\n";
    String ruta = "C://Informes//informeFacturables.xls";
    try {
        FileOutputStream elFichero = new FileOutputStream(ruta);
        try {
            libro.write(elFichero);
            elFichero.close();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta);
        } catch (IOException ex) {
            Logger.getLogger(Informesfacturables.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Informesfacturables.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Excel.InformesRemitosInternos.java

public void GenerarInforme(String desde, String hasta) throws SQLException, FileNotFoundException, IOException {
    HSSFWorkbook libro = new HSSFWorkbook();
    HSSFSheet hoja = libro.createSheet("Resumen");

    /*/*from  ww w.ja v a  2s  .c om*/
     * GENERAR LAS SIGUIENTES HOJAS
     * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y 
     * NUMERO DE CAJA
     * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA
     * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS
     * 
     */

    String ttx = "celda numero :";
    HSSFRow fila = null;
    HSSFCell celda;
    HSSFCell celda1;
    HSSFCell celda2;
    HSSFCell celda3;
    HSSFCell celda4;
    HSSFCell celda5;
    HSSFCell celda6;
    HSSFCell celda7;
    HSSFCell celda8;
    HSSFFont fuente = libro.createFont();
    //fuente.setFontHeight((short)21);
    fuente.setFontName(fuente.FONT_ARIAL);
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    String form = null;
    String sql = "SELECT *,(select depositos.descripcion from depositos where depositos.numero=movimientosdesucursales.depOrigen)as depor,(select depositos.descripcion from depositos where depositos.numero=movimientosdesucursales.depDestino)as depod,(select articulos.NOMBRE from articulos where articulos.ID=movimientosdesucursales.idArticulo)as descA  FROM movimientosdesucursales where fecha between '"
            + desde + "' and '" + hasta + "'";
    System.out.println(sql);
    Transaccionable tra = new Conecciones();
    ResultSet rs = tra.leerConjuntoDeRegistros(sql);
    HSSFCellStyle titulo = libro.createCellStyle();
    titulo.setFont(fuente);
    //titulo.setFillBackgroundColor((short)22);
    titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    //for(int a=0;a < 100;a++){
    int col = 0;
    int a = 0;
    Double total = 0.00;
    if (a == 0) {
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        celda.setCellStyle(titulo);
        celda.setCellValue("Codigo");
        celda1 = fila.createCell(1);
        celda1.setCellStyle(titulo);
        celda1.setCellValue("Articulo");
        celda2 = fila.createCell(2);
        celda2.setCellStyle(titulo);
        celda2.setCellValue("Cantidad");
        celda3 = fila.createCell(3);
        celda3.setCellStyle(titulo);
        celda3.setCellValue("Costo");
        celda4 = fila.createCell(4);
        celda4.setCellStyle(titulo);
        celda4.setCellValue("Remito");
        celda5 = fila.createCell(5);
        celda5.setCellStyle(titulo);
        celda5.setCellValue("Origen");
        celda6 = fila.createCell(6);
        celda6.setCellStyle(titulo);
        celda6.setCellValue("Destino");
        celda7 = fila.createCell(7);
        celda7.setCellStyle(titulo);
        celda7.setCellValue("Fecha");
        celda8 = fila.createCell(8);
        celda8.setCellStyle(titulo);
        celda8.setCellValue("Total");
    }
    while (rs.next()) {
        a++;
        //col=rs.getInt("tipoMovimiento");
        switch (col) {
        case 1:

            break;
        default:

            break;
        }
        fila = hoja.createRow(a);
        celda = fila.createCell(0);
        ttx = ttx;
        total = 0.00;
        celda.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda.setCellValue(rs.getString("idArticulo"));
        celda1 = fila.createCell(1);
        ttx = ttx;
        celda1.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda1.setCellValue(rs.getString("descA"));
        celda2 = fila.createCell(2);
        celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda2.setCellValue(rs.getInt("cantidad"));
        celda3 = fila.createCell(3);
        celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda3.setCellValue(rs.getDouble("costo"));
        total = rs.getInt("cantidad") * rs.getDouble("costo");
        celda4 = fila.createCell(4);
        celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda4.setCellValue(rs.getInt("numeroRemito"));

        celda5 = fila.createCell(5);
        //celda5.setCellFormula(rs.getString("observaciones"));
        celda5.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda5.setCellValue(rs.getString("depor"));
        //celda5.setCellValue(rs.getDate("fecha"));
        celda6 = fila.createCell(6);
        celda6.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda6.setCellValue(rs.getString("depod"));
        celda7 = fila.createCell(7);
        celda7.setCellType(HSSFCell.CELL_TYPE_STRING);
        celda7.setCellValue(rs.getString("fecha"));
        celda8 = fila.createCell(8);
        celda8.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        celda8.setCellValue(total);
    }

    rs.close();
    //texto+="\r\n";
    String ruta = "C://Informes//informedeRemitosInternos.xls";
    try {
        FileOutputStream elFichero = new FileOutputStream(ruta);
        try {
            libro.write(elFichero);
            elFichero.close();
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta);
        } catch (IOException ex) {
            Logger.getLogger(InformesRemitosInternos.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformesRemitosInternos.class.getName()).log(Level.SEVERE, null, ex);
    }

}