廍 戈卜口中
磘
一口月人山
萡 廿水竹日
硦 一口一土廿
從Console看盡人生錯誤百態 100種的錯誤
解決錯誤的方法只有一個,那就是...............吃......早......餐!
搜尋此網誌
windows常用命令
[ 群組原則 ]
開始 → 執行 → gpedit.msc
[ 惡意軟體移除工具 ]
開始 → 執行 → mrt
[ 機碼 ]
開始 → 執行 → regedit
[ 系統設定公用程式 ]
開始 → 執行 → msconfig
[ 控制client端所有網路設備 ]
開始 → 執行 → cmd → ipconfig
開始 → 執行 → gpedit.msc
[ 惡意軟體移除工具 ]
開始 → 執行 → mrt
[ 機碼 ]
開始 → 執行 → regedit
[ 系統設定公用程式 ]
開始 → 執行 → msconfig
[ 控制client端所有網路設備 ]
開始 → 執行 → cmd → ipconfig
開始 → 執行 → cmd → ipconfig/all
[ 顯示封包經過的路由器的IP位址 ]
開始 → 執行 → cmd → tracert (網址或IP)
[ 顯示封包經過的路由器的IP位址 ]
開始 → 執行 → cmd → tracert (網址或IP)
2011年10月25日 星期二
2011年10月21日 星期五
如何用Apache POI读取Excel
來源
看了网上很多的文章,都是一个样子的,自己研究了下POI,把经验和大家分享下。
首先POI是开源组织Apache出品的一个开源jar包,提供了方便解析Excel的API,我们可以非常方便的使用它来读取Excel。这里介绍3.5Final版本。
所需用到的jar包如下:
说到Excel,有2003和2007,格式是不一样的,用POI解析的方法也就不一样,Excel2003主要是使用org.apache.poi.hssf.usermodel包中的类来解析,而Excel2007就是使用org.apache.poi.xssf.usermodel来解析。
解析Excel2003源码
StringBuffer content = new StringBuffer();
解析Excel2007和2003基本一样,只是将HSSFSheet,HSSFCell等都改成XSSFSheet,XSSFCell即可。
另外要提醒大家的是Excel的样式都是基于一个单元格的,所以用HSSFRow.getRowStyle()拿样式会出问题的,不一定会拿到你想要的样式。处理合并单元格是POI的一个难点,只能通过判断当前单元格是否在合并单元格之中,如果是,那此单元格的值便是这个合并单元格的首位置单元格的值,只有通过这样才能来处理合并单元格。
处理合并单元格的代码:
2011年10月3日 星期一
2011年9月30日 星期五
HSSFCellStyle
HSSFCellStyle有两个背景颜色属性,一个叫FillBackgroundColor,另一个叫FillForegroundColor,但其实这指的都是背景颜色,那为什么还有ForegroundColor呢?为了能够帮助大家理解,我们举一个实际的例子,下面这个图案是Excel的一个单元格:
线是白色的,背景是红色的。这里的线其实就是下面的Excel界面中的图案
至于线的颜色则是图案颜色,即白色。
下面罗列一下图案样式及其对应的值:
图案样式 常量
HSSFCellStyle.NO_FILL
HSSFCellStyle.ALT_BARS
HSSFCellStyle.FINE_DOTS
HSSFCellStyle.SPARSE_DOTS
HSSFCellStyle.LESS_DOTS
HSSFCellStyle.LEAST_DOTS
HSSFCellStyle.BRICKS
HSSFCellStyle.BIG_SPOTS
HSSFCellStyle.THICK_FORWARD_DIAG
HSSFCellStyle.THICK_BACKWARD_DIAG
HSSFCellStyle.THICK_VERT_BANDS
HSSFCellStyle.THICK_HORZ_BANDS
HSSFCellStyle.THIN_HORZ_BANDS
HSSFCellStyle.THIN_VERT_BANDS
HSSFCellStyle.THIN_BACKWARD_DIAG
HSSFCellStyle.THIN_FORWARD_DIAG
HSSFCellStyle.SQUARES
HSSFCellStyle.DIAMONDS
2011年9月27日 星期二
備註各種Jar版本
一、POI 3.6
使用.xlsx會出現
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
使用.xlsx會出現
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
2011年9月23日 星期五
正規運算式 Regular Expression
JWorld@TW Java論壇 - Java Regular Expression的學習筆記
Pattern (Java 2 Platform SE 6)
正規運算式 Regular Expression
13-4 正規運算式(Regular Expression)
//範例
以下的程式簡單地示範了幾個常用的method:
package demo.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
public static void main(String[] args) {
// 測試 testString 中是否包含了 aa
String testString = "ABCaaabcaac";
System.out.println("String.contains():\t"+testString.contains("aa"));
// 和上面目的相同,但運用了 regular expression
// 而這其實是利用了 Pattern 的靜態方法matches()
System.out.println("String.matches():\t"+testString.matches(".*aa.*"));
System.out.println("Pattern.matches():\t"+Pattern.matches(".*aa.*",testString));
System.out.println();
// 如果要用相同的 regular expression 測試很多資料
// 可以使用Pattern的靜態方法compile()來編譯
// 之後就可以重覆使用這個pattern的matcher()方法來進行字串比對
String testString2 = "aababcAc";
Pattern pattern = Pattern.compile(".*aa.*");
Matcher matcher = pattern.matcher(testString);
System.out.println("matcher.matches():\t"+matcher.matches());
matcher = pattern.matcher(testString2);
System.out.println("matcher.matches():\t"+matcher.matches());
System.out.println();
// 另外Matcher中還有很多方法可以使用
// 除了用 matcher.matches()可以比對字串是不是符合regular expression
// 也可以利用 matcher.lookingAt()比對字串是不是某個regular expression開頭
pattern = Pattern.compile("aa");
matcher = pattern.matcher(testString);
System.out.println("matcher.matches():\t"+matcher.lookingAt());
matcher = pattern.matcher(testString2);
System.out.println("matcher.matches():\t"+matcher.lookingAt());
System.out.println();
// 想取出字串中符合的區段則可以運用 matcher
// 例如想從下面四個號碼找出手機的格式
// 就可以用 matcher.find()及matcher.group()來取出符合的項目
String testString3 = "0911-111111, 02-22222222 , 0922-222222 , 03-33333333";
pattern = Pattern.compile("\\d{4}-\\d{6}");
matcher = pattern.matcher(testString3);
while (matcher.find()) {
System.out.println("matcher.group():\t"+matcher.group());
}
}
}
而輸出的結果如下:
String.contains(): true
String.matches(): true
Pattern.matches(): true
matcher.matches(): true
matcher.matches(): true
matcher.matches(): false
matcher.matches(): true
matcher.group(): 0911-111111
matcher.group(): 0922-222222
Pattern (Java 2 Platform SE 6)
正規運算式 Regular Expression
13-4 正規運算式(Regular Expression)
//範例
以下的程式簡單地示範了幾個常用的method:
package demo.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
public static void main(String[] args) {
// 測試 testString 中是否包含了 aa
String testString = "ABCaaabcaac";
System.out.println("String.contains():\t"+testString.contains("aa"));
// 和上面目的相同,但運用了 regular expression
// 而這其實是利用了 Pattern 的靜態方法matches()
System.out.println("String.matches():\t"+testString.matches(".*aa.*"));
System.out.println("Pattern.matches():\t"+Pattern.matches(".*aa.*",testString));
System.out.println();
// 如果要用相同的 regular expression 測試很多資料
// 可以使用Pattern的靜態方法compile()來編譯
// 之後就可以重覆使用這個pattern的matcher()方法來進行字串比對
String testString2 = "aababcAc";
Pattern pattern = Pattern.compile(".*aa.*");
Matcher matcher = pattern.matcher(testString);
System.out.println("matcher.matches():\t"+matcher.matches());
matcher = pattern.matcher(testString2);
System.out.println("matcher.matches():\t"+matcher.matches());
System.out.println();
// 另外Matcher中還有很多方法可以使用
// 除了用 matcher.matches()可以比對字串是不是符合regular expression
// 也可以利用 matcher.lookingAt()比對字串是不是某個regular expression開頭
pattern = Pattern.compile("aa");
matcher = pattern.matcher(testString);
System.out.println("matcher.matches():\t"+matcher.lookingAt());
matcher = pattern.matcher(testString2);
System.out.println("matcher.matches():\t"+matcher.lookingAt());
System.out.println();
// 想取出字串中符合的區段則可以運用 matcher
// 例如想從下面四個號碼找出手機的格式
// 就可以用 matcher.find()及matcher.group()來取出符合的項目
String testString3 = "0911-111111, 02-22222222 , 0922-222222 , 03-33333333";
pattern = Pattern.compile("\\d{4}-\\d{6}");
matcher = pattern.matcher(testString3);
while (matcher.find()) {
System.out.println("matcher.group():\t"+matcher.group());
}
}
}
而輸出的結果如下:
String.contains(): true
String.matches(): true
Pattern.matches(): true
matcher.matches(): true
matcher.matches(): true
matcher.matches(): false
matcher.matches(): true
matcher.group(): 0911-111111
matcher.group(): 0922-222222
JavaScript傳中文值
//前一個JSP,optName是下拉選單的名稱
form1.action = "importExcelk.jsp?optName="+form1.fileType.options[form1.fileType.selectedIndex].text;
form1.submit();
//取值的JSP
new String(request.getParameter("aaa").getBytes("ISO-8859-1"), "UTF-8");
form1.action = "importExcelk.jsp?optName="+form1.fileType.options[form1.fileType.selectedIndex].text;
form1.submit();
//取值的JSP
new String(request.getParameter("aaa").getBytes("ISO-8859-1"), "UTF-8");
2011年9月21日 星期三
DecimalFormat 注意事項
1.
Format df = new DecimalFormat("000");
System.out.println(df.format(new Integer("7")));//不能使用型態String,df.format(string)
訂閱:
文章 (Atom)