读取excel文件生成java文件.docx
- 文档编号:5099957
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:16
- 大小:18.93KB
读取excel文件生成java文件.docx
《读取excel文件生成java文件.docx》由会员分享,可在线阅读,更多相关《读取excel文件生成java文件.docx(16页珍藏版)》请在冰豆网上搜索。
读取excel文件生成java文件
ImportsSystem.IO
ImportsSystem.Windows.Forms
ImportsMicrosoft.Office.Interop
PublicClassForm1
PublicStructureTerm
DimkoubenAsString'項番
DimnmAsString'属性名
DimpriAsString'可視性
DimkeiAsString'型
DimisStaticAsString'static
DimtiAsString'初期値
DimsetumeiAsString'説明
EndStructure
PrivatelstAsArrayList
PrivatelstMethodAsArrayList
PrivatelstClassAsNewArrayList
PrivatestrPathAsString=String.Empty
PrivatestrDirAsString=String.Empty
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
lst=NewArrayList
FolderBrowserDialog1.Description="SelectaFolder"
FolderBrowserDialog1.RootFolder=Environment.SpecialFolder.MyComputer
FolderBrowserDialog1.ShowNewFolderButton=False
IfFolderBrowserDialog1.ShowDialog=System.Windows.Forms.DialogResult.OKThen
Me.Label1.Text=FolderBrowserDialog1.SelectedPath
GetAllFile(FolderBrowserDialog1.SelectedPath,lst,"*.xls")
EndIf
EndSub
PrivateSubGetAllFile(ByValpathAsString,ByReflstAsArrayList,ByValstrAsString)
DimstrDirAsString()=System.IO.Directory.GetDirectories(path)
DimstrFileAsString()=System.IO.Directory.GetFiles(path,str)
DimiAsInteger
IfstrFile.Length>0Then
Fori=0TostrFile.Length-1
lst.Add(strFile(i))
Next
EndIf
IfstrDir.Length>0Then
Fori=0TostrDir.Length-1
GetAllFile(strDir(i),lst,str)
Next
EndIf
EndSub
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
FolderBrowserDialog1.Description="SelectaFolder"
FolderBrowserDialog1.RootFolder=Environment.SpecialFolder.MyComputer
FolderBrowserDialog1.ShowNewFolderButton=False
IfFolderBrowserDialog1.ShowDialog=System.Windows.Forms.DialogResult.OKThen
Me.Label2.Text=FolderBrowserDialog1.SelectedPath
EndIf
EndSub
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
DimxlAppExcelFileAsExcel.Application
DimxlBookAsExcel.Workbook
DimxlSheetAsExcel.Worksheet
lstMethod=NewArrayList
ForiAsInteger=0Tolst.Count-1
'生成新的instance
xlAppExcelFile=NewExcel.Application
xlBook=xlAppExcelFile.Workbooks.Open(lst(i))
'不表示Excel
xlAppExcelFile.Visible=False
'禁止显示对话框和警告消息
xlAppExcelFile.DisplayAlerts=False
'取消任务栏中的窗口选项
xlAppExcelFile.ShowWindowsInTaskbar=False
DiminiSheetsAsInteger=xlBook.Sheets.Count
ForindexAsInteger=1ToiniSheets
DimlstMeisaiAsNewArrayList
xlSheet=xlBook.Sheets(index)
If"変更履歴".Equals(xlSheet.Name.Trim)_
Or"変更書".Equals(xlSheet.Name.Trim)Then
ContinueFor
EndIf
If"メソッド名".Equals(xlSheet.Cells(5,"B").Value())Then
IfNotlstMethod.Contains(lst(i))Then
lstMethod.Add(lst(i))
EndIf
ContinueFor
EndIf
lstMeisai.Add("/**********************************************************")
lstMeisai.Add("*第2次 統合ATMスイッチングサービス")
lstMeisai.Add("*")
lstMeisai.Add("*SUBSYSTEMNAME:
維持運用支援システム")
lstMeisai.Add("*SERVICENAME:
(DD書記載の機能名)")
lstMeisai.Add("*FUNCTION:
"+xlSheet.Cells(8,"C").Value())
lstMeisai.Add("*FILENAME:
"+xlSheet.Cells(6,"C").Value())
lstMeisai.Add("*")
lstMeisai.Add("*変更履歴")
lstMeisai.Add("*2010/12/21"+xlSheet.Cells(4,"H").Value()+"@SWTオリジナル作成")
lstMeisai.Add("**********************************************************/")
lstMeisai.Add("package"+xlSheet.Cells(7,"C").Value()&";")
lstMeisai.Add("")
lstMeisai.Add("/**")
lstMeisai.Add("*"+xlSheet.Cells(8,"C").Value()+".
")
DimblnSousakuAsBoolean=False
ForrowIndexAsInteger=1ToxlSheet.UsedRange.Rows.Count
If"操作".Equals(xlSheet.Cells(rowIndex,"B").Value())Then
IfblnSousaku=FalseThen
blnSousaku=True
Else
IfNot(xlSheet.Cells(rowIndex+2,"B").Value()IsNothing_
OrElse"".Equals(xlSheet.Cells(rowIndex+2,"B").Value())_
Or"備考".Equals(xlSheet.Cells(rowIndex+2,"B").Value()))Then
lstMeisai.Add("*機能は以下の通り
")
lstMeisai.Add("*
- ")
- "+xlSheet.Cells(j,"H").Value())
Else
ExitFor
EndIf
Next
IfNot(xlSheet.Cells(rowIndex+2,"B").Value()IsNothing_
OrElse"".Equals(xlSheet.Cells(rowIndex+2,"B").Value())_
Or"備考".Equals(xlSheet.Cells(rowIndex+2,"B").Value()))Then
lstMeisai.Add("*
EndIf
ForjAsInteger=rowIndex+2ToxlSheet.UsedRange.Rows.Count
IfNot(xlSheet.Cells(j,"B").Value()IsNothing_
OrElse"".Equals(xlSheet.Cells(j,"B").Value())_
Or"備考".Equals(xlSheet.Cells(j,"B").Value()))Then
lstMeisai.Add("*
lstMeisai.Add("*
")
lstMeisai.Add("*
")
EndIf
ExitFor
EndIf
EndIf
Next
lstMeisai.Add("*@version$Revision$(2010/08/09)")
lstMeisai.Add("*/")
'継承するクラス
Dimstr1AsString=String.Empty
IfxlSheet.Cells(11,"C").Value()IsNothing_
OrElse("".Equals(xlSheet.Cells(11,"C").Value().ToString.Trim)Or_
"-".Equals(xlSheet.Cells(11,"C").Value().ToString.Trim)Or_
"ない".Equals(xlSheet.Cells(11,"C").Value().ToString.Trim)Or_
"なし".Equals(xlSheet.Cells(11,"C").Value().ToString.Trim))Then
str1+=""
Else
str1+="extends"+xlSheet.Cells(11,"C").Value().ToString.Trim
EndIf
IfxlSheet.Cells(12,"C").Value()IsNothing_
OrElse("".Equals(xlSheet.Cells(12,"C").Value().ToString.Trim)Or_
"-".Equals(xlSheet.Cells(12,"C").Value().ToString.Trim)Or_
"ない".Equals(xlSheet.Cells(12,"C").Value().ToString.Trim)Or_
"なし".Equals(xlSheet.Cells(12,"C").Value().ToString.Trim))Then
str1+=""
Else
str1+="implements"+xlSheet.Cells(12,"C").Value().ToString.Trim
EndIf
lstMeisai.Add(xlSheet.Cells(9,"C").Value()+"class"+xlSheet.Cells(5,"C").Value()+str1+"{")
DimtermListAsNewList(OfTerm)
ForrowIndexAsInteger=1ToxlSheet.UsedRange.Rows.Count
If"属性".Equals(xlSheet.Cells(rowIndex,"B").Value())Then
ForjAsInteger=rowIndex+2ToxlSheet.UsedRange.Rows.Count
IfNot(xlSheet.Cells(j,"B").Value()IsNothing_
OrElse"".Equals(xlSheet.Cells(j,"B").Value()))Then
Dimterm1AsTerm
term1.kouben=xlSheet.Cells(j,"B").Value()
term1.nm=xlSheet.Cells(j,"C").Value()
IfLenC(term1.nm)<>term1.nm.LengthThen
MessageBox.Show(lst(i)+"の"+xlSheet.Name+" 全角エラー:
"+j.ToString+"行->属性名:
"+term1.nm)
ExitSub
EndIf
term1.pri=xlSheet.Cells(j,"D").Value()
term1.kei=xlSheet.Cells(j,"E").Value()
If"○".Equals(xlSheet.Cells(j,"F").Value())Then
term1.isStatic="static"
Else
term1.isStatic=""
EndIf
term1.ti=xlSheet.Cells(j,"G").Value()
term1.setumei=xlSheet.Cells(j,"H").Value()
termList.Add(term1)
Else
ExitFor
EndIf
Next
EndIf
Next
ForkAsInteger=0TotermList.Count-1
lstMeisai.Add("")
lstMeisai.Add("/**")
lstMeisai.Add("*"+termList(k).setumei+".
")
lstMeisai.Add("*/")
lstMeisai.Add(""+termList(k).pri+""+termList(k).isStatic+termList(k).kei+""+termList(k).nm+"="+termList(k).ti+";")
Next
ForkAsInteger=0TotermList.Count-1
lstMeisai.Add("")
lstMeisai.Add("/**")
lstMeisai.Add("*"+termList(k).setumei+"を取得する.")
lstMeisai.Add("*@return"+termList(k).nm+""+termList(k).setumei)
lstMeisai.Add("*/")
If"boolean".Equals(termList(k).kei.ToLower)Then
lstMeisai.Add("public"+termList(k).kei+""+"is"+termList(k).nm.Substring(0,1).ToUpper+termList(k).nm.Substring
(1)+"(){")
Else
lstMeisai.Add("public"+termList(k).kei+""+"get"+termList(k).nm.Substring(0,1).ToUpper+termList(k).nm.Substring
(1)+"(){")
EndIf
lstMeisai.Add("return"+termList(k).nm+";")
lstMeisai.Add("}")
lstMeisai.Add("")
lstMeisai.Add("/**")
lstMeisai.Add("*"+termList(k).setumei+"を設定する.")
lstMeisai.Add("*@param"+termList(k).nm+""+termList(k).kei+""+termList(k).setumei)
lstMeisai.Add("*/")
lstMeisai.Add("publicvoid"+"set"+termList(k).nm.Substring(0,1).ToUpper+termList(k).nm.Substring
(1)+"("+termList(k).kei+""+termList(k).nm+"){")
lstMeisai.Add("this."+termList(k).nm+"="+termList(k).nm+";")
lstMeisai.Add("}")
Next
strPath=xlSheet.Cells(7,"C").Value().ToString.Replace(".","/")+"/"+xlSheet.Cells(6,"C").Value()
strDir=xlSheet.Cells(7,"C").Value().ToString.Replace(".","/")
CreateJavaFile(lstMeisai)
Next
Next
MessageBox.Show("OK")
xlSheet=Nothing
xlBook.Close()
xlBook=Nothing
xlAppExcelFile.Quit()
xlAppExcelFile=Nothing
EndSub
PrivateSubCreateJavaFile(ByVallstAsArrayList)
DimpathAsString=Me.Label2.Text+"\"+strPath
DimdirAsString=Me.Label2.Text+"\"+strDir
IfSystem.IO.Directory.Exists(dir)=FalseThen
System.IO.Directory.CreateDirectory(dir)
EndIf
IfNotFile.Exists(path)Then
File.Create(path).Close()
EndIf
IfNotlstClass.Contains(path)Then
lstClass.Add(path)
EndIf
DimfsAsNewFileStream(path,FileMode.Create)
DimfwAsNewStreamWriter(fs)
ForiAsInteger=0Tolst.Count-1
fw.WriteLine(lst(i))
Next
fw.Close()
fs.Close()
EndSub
PrivateFunctionLenC(ByValstrAsString)AsInteger
DimnAsInteger
DimStrLenAsInteger
Forn=1ToLen(str)
IfAscW(Mid(str,n,1))>256Then
StrLen=StrLen+2
Else
StrLen=StrLen+1
EndIf
Next
ReturnStrLen
EndFunction
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
DimxlAppExcelFileAsExcel.Application
DimxlBookAsExcel.Workbook
DimxlSheetAsExcel.Worksheet
ForiAsInteger=0TolstMethod.Count-1
'生成新的instance
xlAppExcelFile=NewExcel.Application
xlBook=xlAppExcelFile.Workbooks.Open(lstMethod(i))
'不表示Excel
xlAppExcelFile.Visible=False
'禁止显示对话框和警告消息
xlAppExcelFile.DisplayAlerts=Fal
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 读取 excel 文件 生成 java