Sunspl

          Hello,everyone,i am sun. 天道酬勤,笨鳥(niǎo)先飛.
          隨筆 - 47, 文章 - 0, 評(píng)論 - 24, 引用 - 0
          數(shù)據(jù)加載中……

          2008年7月28日

          JAVA架構(gòu)師學(xué)習(xí)方向

          請(qǐng)點(diǎn)我查閱:JAVA架構(gòu)師

          posted @ 2018-10-26 14:12 JavaSuns 閱讀(182) | 評(píng)論 (0)編輯 收藏

          POI操作

          package cc.dynasoft.struts.action;

          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.util.Iterator;
          import java.util.List;
          import java.util.Vector;

          import org.apache.poi.hssf.usermodel.HSSFCell;
          import org.apache.poi.hssf.usermodel.HSSFCellStyle;
          import org.apache.poi.hssf.usermodel.HSSFFont;
          import org.apache.poi.hssf.usermodel.HSSFFooter;
          import org.apache.poi.hssf.usermodel.HSSFHeader;
          import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
          import org.apache.poi.hssf.usermodel.HSSFRow;
          import org.apache.poi.hssf.usermodel.HSSFSheet;
          import org.apache.poi.hssf.usermodel.HSSFWorkbook;
          import org.apache.poi.hssf.util.HSSFColor;
          import org.apache.poi.hssf.util.Region;

          import cc.dynasoft.bean.Department;

          ///import org.apache.poi.hssf.record.HeaderRecorder;

          public class OutputExcel {

          public static boolean outputExcel(ExcelArgs args, List title, List list) {
           try {
            int cellNum = args.getCellNum(); // workbook
            int rowNum = args.getRowNum();
            /**
             * 建立表格設(shè)置。
             */
            HSSFWorkbook wb = new HSSFWorkbook(); // create the new Workbook
            HSSFSheet sheet = wb.createSheet(args.getSheetName()); // create
            /**
             * 打印設(shè)置
             */
            HSSFPrintSetup hps = sheet.getPrintSetup();
            hps.setPaperSize((short) 9); // 設(shè)置A4紙
            // hps.setLandscape(true); // 將頁(yè)面設(shè)置為橫向打印模式
            sheet.setHorizontallyCenter(true); // 設(shè)置打印頁(yè)面為水平居中
            // sheet.setVerticallyCenter(true); // 設(shè)置打印頁(yè)面為垂直居中
            wb.setPrintArea(0, "$A$2:$e$" + rowNum + 2);// 打印區(qū)域設(shè)置.
            /**
             * 設(shè)置表的Footer
             */
            HSSFFooter footer = sheet.getFooter();
            // 設(shè)置footer的位置和顯示的內(nèi)容
            footer.setCenter("Time:" + HSSFFooter.date());
            footer.setRight("Page " + HSSFFooter.page() + " of "
              + HSSFFooter.numPages());
            /**
             * 設(shè)置表的Header
             */
            // 設(shè)置header的位置,共有三種位置和相應(yīng)的顯示設(shè)置
            HSSFHeader header = sheet.getHeader();
            // header.setRight("Center Header");
            // header.setLeft("Left Header");
            header.setCenter(HSSFHeader.font("Stencil-Normal", "Italic")
              + HSSFHeader.fontSize((short) 30) + args.getHeaderTitle());
            // header.endDoubleUnderline();
            header.startUnderline();
            /**
             * 設(shè)置列的寬度
             */
            sheet.setColumnWidth((short) 2,
              (short) ((30 * 8) / ((double) 1 / 10)));
            sheet.setColumnWidth((short) 3,
              (short) ((40 * 8) / ((double) 1 / 10)));
            sheet.setColumnWidth((short) 4,
              (short) ((50 * 8) / ((double) 1 / 20)));
            /**
             * 創(chuàng)建第一行,也就是顯示的標(biāo)題, 可以高置的高度,單元格的格式,顏色,字體等設(shè)置. 同時(shí)可以合并單元格.
             */
            HSSFRow row0 = sheet.createRow(0); // 創(chuàng)建0行
            row0.setHeight((short) 0x300); // 設(shè)直行的高度.
            HSSFFont font2 = wb.createFont(); // 創(chuàng)建字體格式
            font2.setColor(HSSFFont.SS_NONE); // 設(shè)置單元格字體的顏色.
            font2.setFontHeight((short) 700); // 設(shè)置字體大小
            font2.setFontName("Courier New"); // 設(shè)置單元格字體
            HSSFCell cell0 = row0.createCell((short) 0); // 創(chuàng)建0行0列.
            HSSFCellStyle style3 = wb.createCellStyle(); // 創(chuàng)建單元格風(fēng)格.
            style3.setAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
            style3.setAlignment(HSSFCellStyle.ALIGN_CENTER); // /水平居中
            style3.setFont(font2); // 將字體格式加入到單元格風(fēng)格當(dāng)中
            // cell0.setCellType()
            cell0.setCellStyle(style3); // 設(shè)置單元格的風(fēng)格.
            cell0.setCellValue(args.getHeaderTitle()); // 設(shè)置單元的內(nèi)容.
            sheet.addMergedRegion(new Region(0, (short) 0, 0,
              (short) (cellNum - 1)));// 指定合并區(qū)域,前二個(gè)參數(shù)為開(kāi)始處X,Y坐標(biāo).后二個(gè)為結(jié)束的坐標(biāo).
            /**
             * 設(shè)置其它數(shù)據(jù) 設(shè)置風(fēng)格
             */
            HSSFCellStyle style = wb.createCellStyle();
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 設(shè)置單無(wú)格的邊框?yàn)榇煮w
            style.setBottomBorderColor(HSSFColor.BLACK.index); // 設(shè)置單元格的邊框顏色.
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setLeftBorderColor(HSSFColor.BLACK.index);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setRightBorderColor(HSSFColor.BLACK.index);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);
            style.setTopBorderColor(HSSFColor.BLACK.index);
            // style.setWrapText(true);//文本區(qū)域隨內(nèi)容多少自動(dòng)調(diào)整

            // style.setFillForegroundColor(HSSFColor.LIME.index);
            // style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            /**
             * 設(shè)置風(fēng)格1
             */
            HSSFCellStyle style1 = wb.createCellStyle();
            style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 設(shè)置單無(wú)格的邊框?yàn)榇煮w
            style1.setBottomBorderColor(HSSFColor.BLACK.index); // 設(shè)置單元格的邊框顏色.
            style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style1.setLeftBorderColor(HSSFColor.BLACK.index);
            style1.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style1.setRightBorderColor(HSSFColor.BLACK.index);
            style1.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
            style1.setTopBorderColor(HSSFColor.BLACK.index);
            style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);// 最好的設(shè)置Pattern
            // 單元格背景的顯示模式.
            style1.setFillForegroundColor(new HSSFColor.RED().getIndex()); // 設(shè)置單元格背景色;
            style1.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平對(duì)齊方式
            // style1.setWrapText(true);//文本區(qū)域隨內(nèi)容多少自動(dòng)調(diào)整
            // style.setFillPattern(HSSFCellStyle.//);
            // 設(shè)置字體Color,首先創(chuàng)建Font對(duì)象,后對(duì)font設(shè)置,然后做為參數(shù)傳給style
            HSSFFont font = wb.createFont();
            font.setColor(HSSFFont.SS_NONE);
            // font.setFontHeightInPoints((short)24);
            font.setFontName("Courier New");
            // font.setItalic(true);
            // font.setStrikeout(true);//給字體加上刪除線
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            style1.setFont(font);
            /**
             *
             * 設(shè)置第零行表格說(shuō)明行
             *
             *
             *
             */
            HSSFRow row1 = sheet.createRow((short) 1);
            for (int j = 0; j < cellNum; j++) {
             HSSFCell cell = row1.createCell((short) j);
             cell.setCellValue((String) title.get(j));
             cell.setCellStyle(style1);
            }
            // style.setFillPattern(HSSFCellStyle.NO_FILL);

            /**
             * 設(shè)置表的內(nèi)容主體
             */

            Iterator iter = list.iterator();
            for (int i = 2; iter.hasNext(); i++) {
             Department dep = (Department) iter.next();
             HSSFRow row = sheet.createRow((short) i);
             HSSFCell cell5 = row.createCell((short) 0);
             HSSFCell cell1 = row.createCell((short) 1);
             HSSFCell cell2 = row.createCell((short) 2);
             HSSFCell cell3 = row.createCell((short) 3);
             HSSFCell cell4 = row.createCell((short) 4);
             cell5.setCellValue(dep.getId());
             cell5.setCellStyle(style);
             cell1.setCellValue(dep.getParentId());
             cell1.setCellStyle(style);
             cell2.setCellValue(dep.getName());
             cell2.setCellStyle(style);
             cell3.setCellValue(dep.getDescription());
             cell3.setCellStyle(style);
             cell4.setCellValue(dep.getImagePath());
             cell4.setCellStyle(style);
            }
            // Write the output to a file}
            // FileOutputStream fileOut = new
            // FileOutputStream(args.getPath()+args.getFileName());
            /**
             * 對(duì)文件進(jìn)行輸出操作。
             */
            FileOutputStream fileOut = new FileOutputStream(args
              .getPathAndName());
            wb.write(fileOut);
            // fileOut.close();
           } catch (IOException ex) {
            ex.printStackTrace();
           } catch (Exception ex) {
            ex.printStackTrace();
           }
           return true;
          }

          }

          posted @ 2009-06-13 19:52 JavaSuns 閱讀(612) | 評(píng)論 (0)編輯 收藏

          linux創(chuàng)建文件夾命令

          mkdir /home/u1 創(chuàng)建文件夾/home/u1
          chown oracle /home/u1 表示改變目錄所有者為oracle賬戶(hù);
          chgrp dba /home/u1 改變/home/u1目錄為dba所有;
          chmod 755 /home/u1 表示oracle賬戶(hù)對(duì)/home/u1目錄有755權(quán)限;
          rmdir /home/u1 表示刪除/home/u1目錄

          hostname可以查看linux的計(jì)算機(jī)名;
          whoami可以查看當(dāng)前用戶(hù);
          pwd顯示當(dāng)前路徑;
          df查看系統(tǒng)的硬件信息
          ls -lrt l表示顯示詳細(xì)列表,-t表示按時(shí)間排序,-r反向排序

          cat orcl_ora_3436.trc|grep bucket

          以下查看相關(guān)文件內(nèi)容:
          more /etc/oratab
          cat /etc/passwd
          cat /etc/group

          posted @ 2008-07-28 09:01 JavaSuns 閱讀(38656) | 評(píng)論 (4)編輯 收藏

          Linux中復(fù)制文件或目錄的命令(為了響應(yīng)新工作,要學(xué)習(xí)一下LINUX)

          copy命令  

          該命令的功能是將給出的文件或目錄拷貝到另一文件或目錄中,同MSDOS下的copy命令一樣,功能十分強(qiáng)大。  

          語(yǔ)法: cp [選項(xiàng)] 源文件或目錄 目標(biāo)文件或目錄  

          說(shuō)明:該命令把指定的源文件復(fù)制到目標(biāo)文件或把多個(gè)源文件復(fù)制到目標(biāo)目錄中。  

          該命令的各選項(xiàng)含義如下:

          - a 該選項(xiàng)通常在拷貝目錄時(shí)使用。它保留鏈接、文件屬性,并遞歸地拷貝目錄,其作用等于dpR選項(xiàng)的組合。 

          - d 拷貝時(shí)保留鏈接。  

          - f 刪除已經(jīng)存在的目標(biāo)文件而不提示。  

          - i 和f選項(xiàng)相反,在覆蓋目標(biāo)文件之前將給出提示要求用戶(hù)確認(rèn)。回答y時(shí)目標(biāo)文件將被覆蓋,是交互式拷貝。  

          - p 此時(shí)cp除復(fù)制源文件的內(nèi)容外,還將把其修改時(shí)間和訪問(wèn)權(quán)限也復(fù)制到新文件中。  

          - r 若給出的源文件是一目錄文件,此時(shí)cp將遞歸復(fù)制該目錄下所有的子目錄和文件。此時(shí)目標(biāo)文件必須為一個(gè)目錄名。 

          - l 不作拷貝,只是鏈接文件。  

          需要說(shuō)明的是,為防止用戶(hù)在不經(jīng)意的情況下用cp命令破壞另一個(gè)文件,如用戶(hù)指定的目標(biāo)文件名已存在,用cp命令拷貝文件后,這個(gè)文件就會(huì)被新源文件覆蓋,因此,建議用戶(hù)在使用cp命令拷貝文件時(shí),最好使用i選項(xiàng)。

          posted @ 2008-07-28 08:59 JavaSuns 閱讀(2325) | 評(píng)論 (0)編輯 收藏

          主站蜘蛛池模板: 齐齐哈尔市| 桃园县| 郴州市| 张家口市| 宣化县| 商洛市| 安新县| 连州市| 清水河县| 南康市| 新兴县| 修文县| 榆中县| 贵德县| 台东县| 新巴尔虎右旗| 晋宁县| 仲巴县| 洛隆县| 买车| 三都| 北票市| 桓仁| 余庆县| 宾川县| 吴江市| 集贤县| 凉山| 乐至县| 濉溪县| 视频| 射阳县| 南溪县| 武清区| 阳西县| 正宁县| 阿巴嘎旗| 新化县| 沙田区| 满洲里市| 吉林省|