我目前正在一個應用程序,添加到現有的Excel數據輸入電子表格..簡單的權利?我在查找有關工作表格式(邊框,創建超鏈接,背景顏色等)的信息時遇到了問題。我在各處搜索過,大部分我發現的內容都不適合我。我正在運行Visual Studio Pro 2013.智能感覺似乎不適用於我的計算機上的大部分Excel東西,出於某種原因,是否有網站或其他功能以及如何訪問它們?我引用了參考管理器COM部分中的Microsoft Excel 15.0對象庫以及程序集中的Microsoft Office Tools Excel。利用Excel的功能與vb.net(邊界等..)
這裏是我的代碼:
Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Tools.Excel
Imports Microsoft.Office.Core
Imports System.Reflection
Imports System.IO
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
If jobnumtext.Text.Length > 2 And provincetext.Text.Length > 0 And contractnumbertext.Text.Length > 2 And clienttext.Text.Length > 0 Then
thisdate = DateTime.Now
thismonth = Month(thisdate)
name = MonthName(thismonth, True)
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open("\\IP Address\qa_qc\003. Quality Management\005. Project Management\Project Logs\Job Set Up\Job Set Up Log_Current.xlsx")
oSheet = oBook.Worksheets(name.ToString())
Dim sheet As Worksheet = oExcel.ThisWorkbook.Worksheets(0)
Try
With oSheet
If oExcel.WorksheetFunction.CountA(.Cells) <> 0 Then
lrow = .Cells.Find(What:="*",
After:=.Range("A1"),
LookAt:=Excel.XlLookAt.xlPart,
LookIn:=Excel.XlFindLookIn.xlFormulas,
SearchOrder:=Excel.XlSearchOrder.xlByRows,
SearchDirection:=Excel.XlSearchDirection.xlPrevious,
MatchCase:=False).Row
Else
lrow = 1
End If
End With
oSheet.Range("A" & lrow + 1).Value = dateissued.Text
oSheet.Range("B" & lrow + 1).Value = contractnumbertext.Text
oSheet.Range("C" & lrow + 1).Value = clienttext.Text
oSheet.Range("D" & lrow + 1).Value = provincetext.Text
oSheet.Range("E" & lrow + 1).Value = locationtext.Text
oSheet.Range("F" & lrow + 1).Value = attentiontext.Text
oSheet.Range("G" & lrow + 1).Value = foremantext.Text
oSheet.Range("H" & lrow + 1).Value = peopletext.Text
oSheet.Range("I" & lrow + 1).Value = setupbytext.Text
oSheet.Range("J" & lrow + 1).Value = startdate.Text
oSheet.Range("K" & lrow + 1).Value = enddate.Text
oSheet.Range("L" & lrow + 1).Value = Pipeline.ToString()
oSheet.Range("M" & lrow + 1).Value = facility.ToString()
oSheet.Range("N" & lrow + 1).Value = hourly.ToString()
oSheet.Range("O" & lrow + 1).Value = holdback.ToString() & " " & holdbackstext.Text & b.ToString()
oSheet.Range("P" & lrow + 1).Value = Discounts.ToString() & " " & discountstext.Text & dis.ToString()
oSheet.Range("Q" & lrow + 1).Value = LOA.ToString() & " " & lo.ToString() & loatext.Text
oSheet.Range("R" & lrow + 1).Value = RateSchedule.ToString() & " " & rateschedtext.Text
oSheet.Range("S" & lrow + 1).Value = WPS.ToString() & " " & wpstext.Text
oSheet.Range("T" & lrow + 1).Value = projectdesctext.Text
oSheet.Range("U" & lrow + 1).Value = filesname.ToString()
oSheet.Columns("A:T").WrapText = True
oSheet.Columns("A:T").AutoFit()
oExcel.ActiveSheet.Columns("A:A").ColumnWidth = 10
oExcel.ActiveSheet.Columns("B:B").ColumnWidth = 17
oExcel.ActiveSheet.Columns("C:C").ColumnWidth = 20
oExcel.ActiveSheet.Columns("D:D").ColumnWidth = 17
oExcel.ActiveSheet.Columns("E:E").ColumnWidth = 16
oExcel.ActiveSheet.Columns("F:F").ColumnWidth = 12
oExcel.ActiveSheet.Columns("G:G").ColumnWidth = 12
oExcel.ActiveSheet.Columns("H:H").ColumnWidth = 10
oExcel.ActiveSheet.Columns("I:I").ColumnWidth = 12
oExcel.ActiveSheet.Columns("J:J").ColumnWidth = 10
oExcel.ActiveSheet.Columns("K:K").ColumnWidth = 10
oExcel.ActiveSheet.Columns("L:L").ColumnWidth = 8
oExcel.ActiveSheet.Columns("M:M").ColumnWidth = 8
oExcel.ActiveSheet.Columns("N:N").ColumnWidth = 15
oExcel.ActiveSheet.Columns("O:O").ColumnWidth = 15
oExcel.ActiveSheet.Columns("P:P").ColumnWidth = 15
oExcel.ActiveSheet.Columns("Q:Q").ColumnWidth = 15
oExcel.ActiveSheet.Columns("R:R").ColumnWidth = 15
oExcel.ActiveSheet.Columns("S:S").ColumnWidth = 20
oExcel.ActiveSheet.Columns("T:T").ColumnWidth = 80
oExcel.ActiveSheet.Columns("U:U").ColumnWidth = 20
oBook.Save()
oBook.Close()
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
Catch ex As Exception
MsgBox(ex.ToString())
oExcel.Quit()
GC.Collect()
End Try
Else : MessageBox.Show("Sorry you must input all information to Continue!", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
我想創建一個超鏈接列「U」一個完全不知道如何.. 此外,我想添加邊框在文檔的每個新條目。
我不確定如何一切工作與Excel中的庫的引用任何信息的幫助或方向將非常感激!
謝謝大家!
我不斷收到參數違規...這裏是我想到的:oExcel.Range(「U」&lrow.ToString())。Select() oExcel.ActiveSheet.Hyperlinks。添加(地址:=「\\文件位置\ qa_qc \ 003。質量管理\ 005。項目管理\項目日誌\作業設置「) – 2014-10-01 21:32:58
對不起,我顯然不知道如何正確使用這些評論框。 – 2014-10-01 21:57:46
你的intellisense應該告訴你,你需要在add()方法中至少有兩個參數。第一個是你的範圍,第二個是你的地址,你會注意到你的'Range.Select()'方法返回一個'Range'對象,把它放到一個變量中,並把它作爲'Anchor'參數傳遞。 :http://msdn.microsoft.com/en-us/library/office/ff822490.aspx – Steve 2014-10-01 22:03:43