① java格式
紅色是類名(不是你定義的,而是原來就有的,比如Exception),至於怎麼排列,不關事,只要有就可以,比如class test {}都可以,格式化代碼事為了方便
② 求個簡單點的Java程序 100行左右。 需要解釋。
XSSFWorkbook xwb = new XSSFWorkbook(excel);
XSSFSheet sheet = xwb.getSheetAt(0);
for (int i = sheet.getFirstRowNum() + 1; i <= sheet.getPhysicalNumberOfRows(); i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
//metaID
XSSFCell cell0 = row.getCell(0);
if (null == cell0) {
throw new Exception("唯一標識MetaID不能為空!");
}
// 中文標題
XSSFCell cell1 = row.getCell(1);
if (null == cell1) {
throw new Exception("標題不能為空!");
}
// StatutesTitle
XSSFCell cell2 = row.getCell(2);
if (null == cell2) {
throw new Exception("StatutesTitle不能為空!");
}
//StatutesTitle
XSSFCell cell3 = row.getCell(3);
if (null == cell3) {
throw new Exception("法律部門不能為空!");
}
//LegalDepartment
XSSFCell cell4 = row.getCell(4);
if (null == cell4) {
throw new Exception("LegalDepartment不能為空!");
}
//發布部門英文
XSSFCell cell5 = row.getCell(5);
if (null == cell5) {
throw new Exception("發布部門不能為空!");
}
//IssuingDepartment
XSSFCell cell6 = row.getCell(6);
if (null == cell6) {
throw new Exception("IssuingDepartment不能為空!");
}
//發布機構類型
XSSFCell cell7 = row.getCell(7);
if (null == cell7) {
throw new Exception("發布機構類型不能為空!");
}
//IssuingOrganizationType
XSSFCell cell8 = row.getCell(8);
if (null == cell8) {
throw new Exception("IssuingOrganizationType不能為空!");
}
//批准部門
XSSFCell cell9 = row.getCell(9);
//ApprovalDepartment
XSSFCell cell10 = row.getCell(10);
//通過/批准日期
XSSFCell cell11 = row.getCell(11);
//ApprovalDate
XSSFCell cell12 = row.getCell(12);
//發布文號
//TODO 有則必填??
XSSFCell cell13 = row.getCell(13);
//DispatchNo
XSSFCell cell14 = row.getCell(14);
//公布/發布日期
XSSFCell cell15 = row.getCell(15);
if (null == cell15) {
throw new Exception("公布/發布日期不能為空!");
}
//ReleaseDate
XSSFCell cell16 = row.getCell(16);
if (null == cell16) {
throw new Exception("ReleaseDate不能為空!");
}
//施行日期
XSSFCell cell17 = row.getCell(17);
if (null == cell17) {
throw new Exception("施行日期不能為空!");
}
//ImplementationDate
XSSFCell cell18 = row.getCell(18);
if (null == cell18) {
throw new Exception("ImplementationDate不能為空!");
}
//廢止日期
XSSFCell cell19 = row.getCell(19);
//AbolitionDate
XSSFCell cell20 = row.getCell(20);
//歷史沿革
XSSFCell cell21 = row.getCell(21);
//HistoricalDevelopment
XSSFCell cell22 = row.getCell(22);
//時效性
XSSFCell cell23 = row.getCell(23);
if (null == cell23) {
throw new Exception("時效性不能為空!");
}
//Timeliness
XSSFCell cell24 = row.getCell(24);
if (null == cell24) {
throw new Exception("Timeliness不能為空!");
}
//效力級別
XSSFCell cell25 = row.getCell(25);
if (null == cell25) {
throw new Exception("效力級別不能為空!");
}
//EffectivenessGrade
XSSFCell cell26 = row.getCell(26);
if (null == cell26) {
throw new Exception("EffectivenessGrade不能為空!");
}
//來源
XSSFCell cell27 = row.getCell(27);
if (null == cell27) {
throw new Exception("來源不能為空!");
}
//SourceName
XSSFCell cell28 = row.getCell(28);
if (null == cell28) {
throw new Exception("SourceName不能為空!");
}
//地域
XSSFCell cell29 = row.getCell(29);
if (null == cell29) {
throw new Exception("地域不能為空!");
}
//Areas
XSSFCell cell30 = row.getCell(30);
if (null == cell30) {
throw new Exception("Areas不能為空!");
}
//年度
XSSFCell cell31 = row.getCell(31);
if (null == cell31) {
throw new Exception("年度不能為空!");
}
//Year
XSSFCell cell32 = row.getCell(32);
if (null == cell32) {
throw new Exception("Year不能為空!");
}
//主題分類
XSSFCell cell33 = row.getCell(33);
if (null == cell33) {
throw new Exception("主題分類不能為空!");
}
//InstryClassification
XSSFCell cell34 = row.getCell(34);
if (null == cell34) {
throw new Exception("InstryClassification不能為空!");
}
//學科分類
XSSFCell cell35 = row.getCell(35);
if (null == cell35) {
throw new Exception("學科分類不能為空!");
}
//SubjectCategory
XSSFCell cell36 = row.getCell(36);
if (null == cell36) {
throw new Exception("SubjectCategory不能為空!");
}
//中圖法分類
XSSFCell cell37 = row.getCell(37);
if (null == cell37) {
throw new Exception("中圖法分類不能為空!");
}
//CLC
XSSFCell cell38 = row.getCell(38);
if (null == cell38) {
throw new Exception("CLC不能為空!");
}
//案由
XSSFCell cell39 = row.getCell(39);
//CauseOfAction
XSSFCell cell40 = row.getCell(40);
//程序
XSSFCell cell41 = row.getCell(41);
if (null == cell41) {
throw new Exception("程序不能為空!");
}
//Procere
XSSFCell cell42 = row.getCell(42);
if (null == cell42) {
throw new Exception("Procere不能為空!");
}
//編輯提示
XSSFCell cell43 = row.getCell(43);
//EditPrompt
XSSFCell cell44 = row.getCell(44);
//字數
XSSFCell cell45 = row.getCell(45);
//words
XSSFCell cell46 = row.getCell(46);
//試讀比例(字數)
XSSFCell cell47 = row.getCell(47);
if (null == cell47) {
throw new Exception("試讀比例(字數)不能為空!");
}
//Previews
XSSFCell cell48 = row.getCell(48);
if (null == cell48) {
throw new Exception("Previews不能為空!");
}
//文件路徑
XSSFCell cell49 = row.getCell(49);
if (null == cell49) {
throw new Exception("文件路徑不能為空!");
}
//PathFile
XSSFCell cell50 = row.getCell(50);
if (null == cell50) {
throw new Exception("PathFile不能為空!");
}
//資源類型
XSSFCell cell51 = row.getCell(51);
if (null == cell51) {
throw new Exception("資源類型不能為空!");
}
//ResourceType
XSSFCell cell52 = row.getCell(52);
if (null == cell52) {
throw new Exception("ResourceType不能為空!");
}
//價格
XSSFCell cell53 = row.getCell(53);
if (null == cell53) {
throw new Exception("價格不能為空!");
}
//Eprice
XSSFCell cell54 = row.getCell(54);
if (null == cell54) {
throw new Exception("Eprice不能為空!");
}
String metaID = cell0.toString();
String statutesTitle = cell1.toString();
String legalDepartment = cell3.toString();
String issuingDepartment = cell5.toString();
String issuingOrganizationType = cell7.toString();
String approvalDepartment = cell9.toString();
String approvalDepartmentEn = cell10.toString();
String approvalDate = cell11.toString();
String approvalDateEn = cell12.toString();
String dispatchNo = cell13.toString();
String dispatchNoEn = cell14.toString();
String releaseDate = cell15.toString();
String releaseDateEn = cell16.toString();
String implementationDate = cell17.toString();
String implementationDateEn = cell18.toString();
String abolitionDate = "";
String abolitionDateEn = "";
if(cell19 != null){
abolitionDate = cell19.toString();
}
if(cell20 != null){
abolitionDateEn = cell20.toString();
}
String historicalDevelopment = "";
String historicalDevelopmentEn = "";
if(cell21!= null){
historicalDevelopment = cell21.toString();
}
if(cell22 != null){
historicalDevelopmentEn = cell22.toString();
}
String timeliness = cell23.toString();
String effectivenessGrade = cell25.toString();
String sourceName = "";
String sourceNameEn = "";
if(cell25 != null){
sourceName = cell25.toString();
}
if(cell26 != null){
sourceNameEn = cell26.toString();
}
String areas = cell27.toString();
String year = cell29.toString();
String subjectClassify = cell31.toString();
String instryClassification = cell33.toString();
String subjectCategory = cell35.toString();
String clc = cell37.toString();
String causeOfAction = "";
String causeOfActionEn = "";
if(cell39 != null){
causeOfAction = cell39.toString();
}
if(cell40 != null){
causeOfActionEn = cell40.toString();
}
String procere = cell41.toString();
String editPrompt = "";
String editPromptEn = "";
if(cell43 != null){
editPrompt = cell43.toString();
}
if(cell44 != null){
editPromptEn = cell44.toString();
}
String words = "";
String wordsEn = "";
if(cell45 != null){
words = cell45.toString();
}
if(cell46 != null){
wordsEn = cell46.toString();
}
String preViews = cell47.toString();
String pathFile = cell49.toString();
String resourceType = cell51.toString();
String eprice = cell53.toString();
String epriceEn = cell54.toString();
//給入庫賦值
storage.setProctMetaId(metaID);
storage.setProctTitle(statutesTitle);
storage.setProctTitleEn(statutesTitle);
storage.setProctIssuingDepart(issuingDepartment);
storage.setProctIssuingDepartEn(issuingDepartment);
storage.setProctLegalDepartment(legalDepartment);
storage.setProctLegalDepartmentEn(legalDepartment);
storage.setProctIssuingOType(issuingOrganizationType);
storage.setProctIssuingOTypeEn(issuingOrganizationType);
storage.setProctApprovalDepart(approvalDepartment);
storage.setProctApprovalDeparttEn(approvalDepartmentEn);
storage.setProctApprovalDate(approvalDate);
storage.setProctApprovalDateEn(approvalDateEn);
storage.setProctDispatchNo(dispatchNo);
storage.setProctDispatchNoEn(dispatchNoEn);
storage.setProctReleaseDate(releaseDate);
storage.setProctReleaseDateEn(releaseDateEn);
storage.setProctImplementDate(implementationDate);
storage.setProctImplementDateEn(implementationDateEn);
storage.setProctAbolitionDate(abolitionDate);
storage.setProctAbolitionDateEn(abolitionDateEn);
storage.setProctHistoricalDevelop(historicalDevelopment);
storage.setProctHistoricalDevelopEn(historicalDevelopmentEn);
storage.setProctTimeliness(timeliness);
storage.setProctTimelinessEn(timeliness);
storage.setProctEffectivenessGrade(effectivenessGrade);
storage.setProctEffectivenessGradeEn(effectivenessGrade);
storage.setProctSourceName(sourceName);
storage.setProctSourceNameEn(sourceNameEn);
storage.setProctAreas(areas);
storage.setProctAreasEn(areas);
storage.setProctYear(year);
storage.setProctYearEn(year);
storage.setProctSubjectClass(subjectClassify);
storage.setProctSubjectClassEn(subjectClassify);
storage.setProctInstryClassifica(instryClassification);
storage.setProctInstryClassificaEn(instryClassification);
storage.setProctSubjectCategory(subjectCategory);
storage.setProctSubjectCategoryEn(subjectCategory);
storage.setProctCLC(clc);
storage.setProctCLCEn(clc);
storage.setProctCauseOfAction(causeOfAction);
storage.setProctCauseOfActionEn(causeOfActionEn);
storage.setProctProcere(procere);
storage.setProctProcereEn(procere);
storage.setProctEditPrompt(editPrompt);
storage.setProctEditPromptEn(editPromptEn);
storage.setProctWords(words);
storage.setProctWordsEn(wordsEn);
storage.setProctPreviews(preViews);
storage.setProctPreviewsEn(preViews);
storage.setProctPathFile(pathFile);
storage.setProctPathFileEn(pathFile);
storage.setProctResourceType(resourceType);
storage.setProctResourceTypeEn(resourceType);
storage.setProctEprice(eprice);
storage.setProctEpriceEn(epriceEn);
this.save(storage);
}
}
③ Java的基本格式
基本格式來:修飾符 class 類名(程序代自碼)
意義:Java中的程序代碼都必須放在一個類中,對於類初學者可以簡單地把它理解為一個java程序;類需要使用class作為關鍵字定義;而在class的前面可以有一些修飾符。
(3)java前進幾格擴展閱讀
編寫java時,特別需要注意的幾個書寫格式常見的錯誤:
1.java中的程序代碼中功能執行語句的最後都必須用(;)結束。
這里需要注意的是,在程序中不要將英文的分號(;)誤寫成中文的分號(;) ,如果寫成了中文的分號,編譯器會報告「Invalid character」(無效字元)這樣的錯誤信息。
2.Java語言是嚴格區分大小寫的。在定義類時,不能將class寫成Class,否則編譯會報錯。程序中定義一個computer的同時,還可以定義一個Computer,computer和Computer是兩個全完不同的符號,在使用的時候需要注意。
3. 在編寫java代碼的時候為了便於閱讀,通常會使用一種良好的格式進行排版,但這並不是必須的,我們也可以在兩個單詞或者符號之間任意換行。