1、Imports System.IOImports System.Windows.FormsImports Microsoft.Office.InteropPublic Class Form1Public Structure TermDim kouben As String Dim nm As String Dim pri As String Dim kei As String Dim isStatic As String staticDim ti As String Dim setumei As String hEnd StructurePrivate lst As ArrayListPriv
2、ate lstMethod As ArrayListPrivate lstClass As New ArrayListPrivate strPath As String = String.EmptyPrivate strDir As String = String.EmptyPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clicklst = New ArrayListFolderBrowserDialog1.Description = “
3、Select a Folder“FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputerFolderBrowserDialog1.ShowNewFolderButton = FalseIf FolderBrowserDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK ThenMe.Label1.Text = FolderBrowserDialog1.SelectedPathGetAllFile(FolderBrowserDialog1.Select
4、edPath, lst, “*.xls“)End IfEnd SubPrivate Sub GetAllFile(ByVal path As String, ByRef lst As ArrayList, ByVal str As String)Dim strDir As String() = System.IO.Directory.GetDirectories(path)Dim strFile As String() = System.IO.Directory.GetFiles(path, str)Dim i As IntegerIf strFile.Length 0 ThenFor i =
5、 0 To strFile.Length - 1lst.Add(strFile(i)NextEnd IfIf strDir.Length 0 ThenFor i = 0 To strDir.Length - 1GetAllFile(strDir(i), lst, str)NextEnd IfEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickFolderBrowserDialog1.Description = “Sele
6、ct a Folder“FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputerFolderBrowserDialog1.ShowNewFolderButton = FalseIf FolderBrowserDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK ThenMe.Label2.Text = FolderBrowserDialog1.SelectedPathEnd IfEnd SubPrivate Sub Button3_Click(ByV
7、al sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickDim xlAppExcelFile As Excel.ApplicationDim xlBook As Excel.WorkbookDim xlSheet As Excel.WorksheetlstMethod = New ArrayListFor i As Integer = 0 To lst.Count - 1instancexlAppExcelFile = New Excel.ApplicationxlBook = xlAppExc
8、elFile.Workbooks.Open(lst(i)ExcelxlAppExcelFile.Visible = FalsexlAppExcelFile.DisplayAlerts = FalsexlAppExcelFile.ShowWindowsInTaskbar = FalseDim iniSheets As Integer = xlBook.Sheets.CountFor index As Integer = 1 To iniSheetsDim lstMeisai As New ArrayListxlSheet = xlBook.Sheets(index)If “s“.Equals(x
9、lSheet.Name.Trim) _Or “.Equals(xlSheet.Name.Trim) ThenContinue ForEnd IfIf “.Equals(xlSheet.Cells(5, “B“).Value() ThenIf Not lstMethod.Contains(lst(i) ThenlstMethod.Add(lst(i)End IfContinue ForEnd IflstMeisai.Add(“/*“)lstMeisai.Add(“ * 2yATM“)lstMeisai.Add(“ *“)lstMeisai.Add(“ * SUBSYSTEM NAME : S“)
10、lstMeisai.Add(“ * SERVICE NAME : dC“)lstMeisai.Add(“ * FUNCTION : “ + xlSheet.Cells(8, “C“).Value()lstMeisai.Add(“ * FILE NAME : “ + xlSheet.Cells(6, “C“).Value()lstMeisai.Add(“ *“)lstMeisai.Add(“ * s“)lstMeisai.Add(“ * 2010/12/21 “ + xlSheet.Cells(4, “H“).Value() + “ SWT “)lstMeisai.Add(“*/“)lstMei
11、sai.Add(“package “ + xlSheet.Cells(7, “C“).Value() “)lstMeisai.Add(“)lstMeisai.Add(“/*“)lstMeisai.Add(“ * “ + xlSheet.Cells(8, “C“).Value() + “.“)Dim blnSousaku As Boolean = FalseFor rowIndex As Integer = 1 To xlSheet.UsedRange.Rows.CountIf “.Equals(xlSheet.Cells(rowIndex, “B“).Value() ThenIf blnSou
12、saku = False ThenblnSousaku = TrueElseIf Not (xlSheet.Cells(rowIndex + 2, “B“).Value() Is Nothing _OrElse “.Equals(xlSheet.Cells(rowIndex + 2, “B“).Value() _Or “.Equals(xlSheet.Cells(rowIndex + 2, “B“).Value() ThenlstMeisai.Add(“ * C“)lstMeisai.Add(“ * “)End IfFor j As Integer = rowIndex + 2 To xlSh
13、eet.UsedRange.Rows.CountIf Not (xlSheet.Cells(j, “B“).Value() Is Nothing _OrElse “.Equals(xlSheet.Cells(j, “B“).Value() _Or “.Equals(xlSheet.Cells(j, “B“).Value() ThenlstMeisai.Add(“ * “ + xlSheet.Cells(j, “H“).Value()ElseExit ForEnd IfNextIf Not (xlSheet.Cells(rowIndex + 2, “B“).Value() Is Nothing
14、_OrElse “.Equals(xlSheet.Cells(rowIndex + 2, “B“).Value() _Or “.Equals(xlSheet.Cells(rowIndex + 2, “B“).Value() ThenlstMeisai.Add(“ * “)lstMeisai.Add(“ * “)lstMeisai.Add(“ * “)End IfExit ForEnd IfEnd IfNextlstMeisai.Add(“ * version $Revision$(2010/08/09)“)lstMeisai.Add(“*/“)Dim str1 As String = Stri
15、ng.EmptyIf xlSheet.Cells(11, “C“).Value() Is Nothing _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
16、str1 += “Elsestr1 += “ extends “ + xlSheet.Cells(11, “C“).Value().ToString.TrimEnd IfIf xlSheet.Cells(12, “C“).Value() Is Nothing _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().T
17、oString.Trim) Or _“.Equals(xlSheet.Cells(12, “C“).Value().ToString.Trim) Thenstr1 += “Elsestr1 += “ implements “ + xlSheet.Cells(12, “C“).Value().ToString.TrimEnd IflstMeisai.Add(xlSheet.Cells(9, “C“).Value() + “ class “ + xlSheet.Cells(5, “C“).Value() + str1 + “ “)Dim termList As New List(Of Term)F
18、or rowIndex As Integer = 1 To xlSheet.UsedRange.Rows.CountIf “.Equals(xlSheet.Cells(rowIndex, “B“).Value() ThenFor j As Integer = rowIndex + 2 To xlSheet.UsedRange.Rows.CountIf Not (xlSheet.Cells(j, “B“).Value() Is Nothing _OrElse “.Equals(xlSheet.Cells(j, “B“).Value() ThenDim term1 As Termterm1.kou
19、ben = xlSheet.Cells(j, “B“).Value()term1.nm = xlSheet.Cells(j, “C“).Value()If LenC(term1.nm) “ + term1.nm)Exit SubEnd Ifterm1.pri = xlSheet.Cells(j, “D“).Value()term1.kei = xlSheet.Cells(j, “E“).Value()If “.Equals(xlSheet.Cells(j, “F“).Value() Thenterm1.isStatic = “static “Elseterm1.isStatic = “End
20、Ifterm1.ti = xlSheet.Cells(j, “G“).Value()term1.setumei = xlSheet.Cells(j, “H“).Value()termList.Add(term1)ElseExit ForEnd IfNextEnd IfNextFor k As Integer = 0 To termList.Count - 1lstMeisai.Add(“)lstMeisai.Add(“ /*“)lstMeisai.Add(“ * “ + termList(k).setumei + “.“)lstMeisai.Add(“ */“)lstMeisai.Add(“
21、“ + termList(k).pri + “ “ + termList(k).isStatic + termList(k).kei + “ “ + termList(k).nm + “ = “ + termList(k).ti + “;“)NextFor k As Integer = 0 To termList.Count - 1lstMeisai.Add(“)lstMeisai.Add(“ /*“)lstMeisai.Add(“ * “ + termList(k).setumei + “.“)lstMeisai.Add(“ * return “ + termList(k).nm + “ “
22、 + termList(k).setumei)lstMeisai.Add(“ */“)If “boolean“.Equals(termList(k).kei.ToLower) ThenlstMeisai.Add(“ public “ + termList(k).kei + “ “ + “is“ + termList(k).nm.Substring(0, 1).ToUpper + termList(k).nm.Substring(1) + “() “)ElselstMeisai.Add(“ public “ + termList(k).kei + “ “ + “get“ + termList(k
23、).nm.Substring(0, 1).ToUpper + termList(k).nm.Substring(1) + “() “)End IflstMeisai.Add(“ return “ + termList(k).nm + “;“)lstMeisai.Add(“ “)lstMeisai.Add(“)lstMeisai.Add(“ /*“)lstMeisai.Add(“ * “ + termList(k).setumei + “O.“)lstMeisai.Add(“ * param “ + termList(k).nm + “ “ + termList(k).kei + “ “ + t
24、ermList(k).setumei)lstMeisai.Add(“ */“)lstMeisai.Add(“ public void “ + “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(“ “)NextstrPa
25、th = xlSheet.Cells(7, “C“).Value().ToString.Replace(“.“, “/“) + “/“ + xlSheet.Cells(6, “C“).Value()strDir = xlSheet.Cells(7, “C“).Value().ToString.Replace(“.“, “/“)CreateJavaFile(lstMeisai)NextNextMessageBox.Show(“OK“)xlSheet = NothingxlBook.Close()xlBook = NothingxlAppExcelFile.Quit()xlAppExcelFile
26、 = NothingEnd SubPrivate Sub CreateJavaFile(ByVal lst As ArrayList)Dim path As String = Me.Label2.Text + “ + strPathDim dir As String = Me.Label2.Text + “ + strDirIf System.IO.Directory.Exists(dir) = False ThenSystem.IO.Directory.CreateDirectory(dir)End IfIf Not File.Exists(path) ThenFile.Create(pat
27、h).Close()End IfIf Not lstClass.Contains(path) ThenlstClass.Add(path)End IfDim fs As New FileStream(path, FileMode.Create)Dim fw As New StreamWriter(fs)For i As Integer = 0 To lst.Count - 1fw.WriteLine(lst(i)Nextfw.Close()fs.Close()End SubPrivate Function LenC(ByVal str As String) As IntegerDim n As
28、 IntegerDim StrLen As IntegerFor n = 1 To Len(str)If AscW(Mid(str, n, 1) 256 ThenStrLen = StrLen + 2ElseStrLen = StrLen + 1End IfNextReturn StrLenEnd FunctionPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim xlAppExcelFile As Excel.Applica
29、tionDim xlBook As Excel.WorkbookDim xlSheet As Excel.WorksheetFor i As Integer = 0 To lstMethod.Count - 1instancexlAppExcelFile = New Excel.ApplicationxlBook = xlAppExcelFile.Workbooks.Open(lstMethod(i)ExcelxlAppExcelFile.Visible = FalsexlAppExcelFile.DisplayAlerts = FalsexlAppExcelFile.ShowWindowsI
30、nTaskbar = FalseDim iniSheets As Integer = xlBook.Sheets.CountFor index As Integer = 1 To iniSheetsxlSheet = xlBook.Sheets(index)If LenC(xlSheet.Cells(5, “C“).Value() 0 Thenstr1 = lstReturn(0).ToString.Split(“)(0)End IfIf lstYinsu.Count 0 Thenstr2 = lstYinsu(0).ToString.Split(“)(1) + “ “ + lstYinsu(
31、0).ToString.Split(“)(0)End IfIf lstYinsu.Count 1 ThenFor n As Integer = 1 To lstYinsu.Count - 1str2 += “,“ + lstYinsu(n).ToString.Split(“)(1) + “ “ + lstYinsu(n).ToString.Split(“)(0)NextEnd Iffw.WriteLine(“ “ + xlSheet.Cells(10, “C“).Value() + “ “ + str1 + “ “ + xlSheet.Cells(5, “C“).Value() + “(“ +
32、 str2 + “) “)fw.WriteLine(“)Dim int131 As Integer = 0If lstCaozuo(0).ToString.Trim.Contains(“g“) _Or lstCaozuo(0).ToString.Trim.Contains(“g“) ThenFor m As Integer = 1 To lstCaozuo.Count - 1If lstCaozuo(m).ToString.Trim.Contains(“) Thenint131 = mExit ForEnd IfNextEnd IfIf int131 0 ThenFor j As Intege
33、r = 0 To int131 - 1If lstCaozuo(j).ToString.Trim.Contains(“g“) _And lstCaozuo(j).ToString.Trim.Contains(“) _And lstCaozuo(j).ToString.Trim.Contains(“) ThenDim intspace As Integer = lstCaozuo(j).ToString.Trim.IndexOf(“)Dim intfrom As Integer = lstCaozuo(j).ToString.Trim.IndexOf(“g“)Dim intto As Integ
34、er = lstCaozuo(j).ToString.Trim.IndexOf(“)Dim strGet As String = lstCaozuo(j).ToString.Trim.Substring(intfrom, intto - intfrom)strGet = strGet.Replace(“, “).Replace(“, “).Replace(“g“, “)fw.WriteLine(“ /“ + lstCaozuo(j).ToString.Trim.Substring(intspace + 1, intfrom)fw.WriteLine(“ “ + strGet.Split(“)(
35、1) + “ “ + strGet.Split(“)(0) + “ = “ + strGet.Split(“)(2) + “;“)fw.WriteLine(“)Elsefw.WriteLine(“ /“ + lstCaozuo(j).ToString.Trim.Replace(“, “)End IfNextEnd IfIf lstExp.Count 0 Thenfw.WriteLine(“ try “)End IfIf int131 0 Thenfw.WriteLine(“ “)End Iffw.WriteLine(“)fw.WriteLine(“ “)fw.Close()fs.Close()
36、NextNextMessageBox.Show(“OK“)xlSheet = NothingxlBook.Close()xlBook = NothingxlAppExcelFile.Quit()xlAppExcelFile = NothingEnd SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickDim lstJava As New ArrayListGetAllFile(Me.Label2.Text, lstJava, “*.java“)For i As Integer = 0 To lstJava.Count - 1Dim fs As New FileStream(lstJava(i), FileMode.Append)Dim fw As New StreamWriter(fs)fw.WriteLine(“)fw.WriteLine(“)fw.WriteLine(“)fw.Close()fs.Close()NextMessageBox.Show(“OK“)End SubEnd Class