I will save you the google step. This will export your materials out of a quote.
Tom Osen
Imports Microsoft.Office.Interop.Excel
Private Sub CostedBOM()
'// ** Place Event Handling Code Here **
Dim edvQuoteMtlView As EpiDataView = CType(oTrans.EpiDataViews("JobMtl"), EpiDataView)
Dim edvVendPartView AS EpiDataView = CType(oTrans.EpiDataViews("VendPart"), EpiDataView)
Dim edvVendPBrkView AS EpiDataView = CType(oTrans.EpiDataViews("VendPBrk"), EpiDataView)
Dim edvQuoteHead As EpiDataView = CType(oTrans.EpiDataViews("QuoteHed"), EpiDataView)
Dim inQuoteNum, inQuoteLine, inNetWeight As Integer
Dim workbookLocation, strIncoTerms, strVendor As String
workbookLocation = "\\fileserver\doclinks\quote\" + CStr(edvQuoteMtlView.dataView(edvQuoteMtlView.Row)("QuoteNum")) + "_QuoteWorkbook.xls"
' check to see if the file is not open and exists
If System.IO.File.Exists(workbookLocation) = True _
And Not IsFileOpen(workbookLocation) Then
Dim oExcel As Microsoft.Office.Interop.Excel.Application
oExcel = CreateObject("Excel.Application")
oExcel.Application.Visible = False
Dim oWorkbooks As Object = oExcel.Application.Workbooks.Open(WorkbookLocation)
Dim workbookRow As Integer = 15
Dim strRange, quoteTeam, strClass As String
Dim inLeadTime, inMOQ, inColumn As Integer
Dim inOnHandQty, inAveCost As Decimal
Dim decPriceBreak(8, 1) As Decimal
Dim blSPL, blWholeUnit As Boolean
oWorkbooks = oWorkbooks.Worksheets("Costed BOM")
oExcel.Application.Sheets("Costed BOM").Select
' Set the part weight to the FG part
quoteTeam = edvQuoteHead.dataView(0)("Character08")
PartInfo(oExcel.Application.Cells(1, 5).Value, inLeadTime, inOnHandQty, inNetWeight, blWholeUnit, quoteTeam)
inLeadTime = 0
oExcel.Application.Cells(4, 5).Value = inNetWeight
oExcel.Application.Cells(8, 14).Value = System.DateTime.Now
' msgbox("Lead time at Start = " & CStr(inLeadtime))
For i as integer = 0 to edvQuoteMtlView.dataView.Count - 1
' If edvQuoteMtlView.dataView(edvQuoteMtlView.Row)("QuoteNum") = inQuoteNum _
' And edvQuoteMtlView.dataView(edvQuoteMtlView.Row)("QuoteLine") = inQuoteLine Then
' copy and paste the row so we don't care how many parts this BOM has. We can go to the limit of Excel rows
oExcel.Application.Range("15:15").Select
oExcel.Application.Selection.Copy
workbookRow += 1
strRange = CStr(workbookRow) + ":" + CStr(workbookRow)
oExcel.Application.Range(strRange).Select
oExcel.Application.Selection.Insert(-4121)
' Initalize the variables for this part
inLeadTime = 0
inMOQ = 0
inOnHandQty = 0
inAveCost = 0
PartCost(edvQuoteMtlView.dataView(i)("PartNum"), inAveCost)
'Find the supplier price list information
If edvQuoteMtlView.dataView(i)("BuyIt") _
And edvQuoteMtlView.dataView(i)("VendorNum") <> 0 Then
SupplierPriceList(edvQuoteMtlView.dataView(i)("VendorNum"), edvQuoteMtlView.dataView(i)("PartNum"), inLeadTime, inMOQ, blSPL)
For idxVendPart As Integer = 0 to edvVendPartView.dataView.Count - 1
' inLeadTime = edvVendPartView.dataView(idxVendPart)("LeadTime")
strIncoTerms = edvVendPartView.dataView(idxVendPart)("ShortChar01")
strVendor = edvVendPartView.dataView(idxVendPart)("VendorName")
' For inBrk As Integer = 0 to 8
' decPriceBreak(inBrk, 1) = edvVendPartView.dataView(inBrk)("BaseUnitPrice")
' Next
Next
End If 'edvQuoteMtlView.dataView(i)("VendorNum") <> 0
' msgbox( edvQuoteMtlView.dataView(i)("PartNum") & " Lead time after SPL = " & CStr(inLeadtime) & " " & quoteTeam)
PartInfo(edvQuoteMtlView.dataView(i)("PartNum"), inLeadTime, inOnHandQty, inNetWeight, blWholeUnit, quoteTeam)
' msgbox("Lead time after PartInfo = " & CStr(inLeadtime) & " " & quoteTeam)
If inLeadTime = 0 Then
inLeadTime = edvQuoteMtlView.dataView(i)("LeadTime")
' msgbox("Lead time after screen = " & CStr(inLeadtime) & " " & quoteTeam)
End If
oExcel.Application.Cells(workbookRow, 1).Value = Math.Ceiling((inLeadTime / 7)) ' RoundUp((inLeadTime / 7)) 'A
' oExcel.Application.Cells(workbookRow, 2).Value = quoteTeam 'B
oExcel.Application.Cells(workbookRow, 3).Value = edvQuoteMtlView.dataView(i)("PartNum") 'C
oExcel.Application.Cells(workbookRow, 4).Value = edvQuoteMtlView.dataView(i)("Description") 'D
oExcel.Application.Cells(workbookRow, 5).Value = edvQuoteMtlView.dataView(i)("QtyPer") 'E
oExcel.Application.Cells(workbookRow, 6).Value = edvQuoteMtlView.dataView(i)("IUM") 'F
If blWholeUnit Then
oExcel.Application.Cells(workbookRow, 7).Value = "Yes" 'G
Else
oExcel.Application.Cells(workbookRow, 7).Value = "No"
End If
oExcel.Application.Cells(workbookRow, 8).Value = inMOQ 'H
oExcel.Application.Cells(workbookRow, 9).Value = edvQuoteMtlView.dataView(i)("EstScrap") / 100 'I
' oExcel.Application.Cells(workbookRow, 10).Value = edvQuoteMtlView.dataView(i)("Number13") '
oExcel.Application.Cells(workbookRow, 12).Value = inAveCost 'L
' oExcel.Application.Cells(workbookRow, 11).Value = edvQuoteMtlView.dataView(i)("Number15") '
oExcel.Application.Cells(workbookRow, 14).Value = inOnHandQty 'N
' If SPL then use the price breaks for the data else use the average cost
oExcel.Application.Cells(workbookRow, 18).Value = edvQuoteMtlView.dataView(i)("Number11") 'R
oExcel.Application.Cells(workbookRow, 24).Value = edvQuoteMtlView.dataView(i)("Number12") 'X
oExcel.Application.Cells(workbookRow, 30).Value = edvQuoteMtlView.dataView(i)("Number13") 'AD
oExcel.Application.Cells(workbookRow, 36).Value = edvQuoteMtlView.dataView(i)("Number14") 'AJ
oExcel.Application.Cells(workbookRow, 42).Value = edvQuoteMtlView.dataView(i)("Number15") 'AP
oExcel.Application.Cells(workbookRow, 48).Value = edvQuoteMtlView.dataView(i)("Number16") 'AV
oExcel.Application.Cells(workbookRow, 54).Value = edvQuoteMtlView.dataView(i)("Number17") 'BB
oExcel.Application.Cells(workbookRow, 60).Value = edvQuoteMtlView.dataView(i)("Number18") 'BH
oExcel.Application.Cells(workbookRow, 66).Value = edvQuoteMtlView.dataView(i)("Number19") 'BN
oExcel.Application.Cells(workbookRow, 71).Value = strVendor 'BS
oExcel.Application.Cells(workbookRow, 72).Value = strIncoTerms 'BT
Next
oExcel.Application.ActiveWorkbook.Save
oExcel.Application.Workbooks.Close()
RCO(oWorkbooks)
oExcel.Application.Quit()
RCO(oExcel)
oWorkbooks = Nothing
oExcel = Nothing
GC.Collect()
MsgBox("Costed BOM has finished downloading into the quote workbook." , MsgBoxStyle.OkOnly , "Costed BOM" )
Else
MsgBox("something is wrong with the file " & vbcrlf & "File location is " & workbookLocation _
& vbcrlf & "Is the file open " & CStr(IsFileOpen(workbookLocation)), MsgBoxStyle.OkOnly or MsgBoxStyle.Critical, "Quote Workbook Information" )
End If
edvQuoteMtlView = Nothing
edvVendPartView = Nothing
edvVendPBrkView = Nothing
edvQuoteHead = Nothing
End Sub
Public Sub RCO(obj As Object)
' This releases all the com objects that where created
Try
Dim intRel As Integer = 0
Do
intRel = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
Loop While intRel > 0
Catch ex As Exception
msgbox("Error releasing object" & ex.ToString,vbOKOnly,"Close Excel Error")
obj = Nothing
End Try
End Sub
--- In vantage@yahoogroups.com, "jckinneman" <jckinneman@...> wrote:
>
> I have used your approach only to read information from a very structured Excel Workbook.
>
> To read AND write to Excel I use the Microsoft.Office.Interop.Excel assembly. This exposes all of the capabilities of Excel and lets me manipulate the spreadsheet anyway I need to.
>
> You may need to copy Microsoft.Office.Interop.Excel.dll into the Epicor /client directory. After that use the add custom assembly and the appropriate using/imports Microsoft.Office.Interop.Excel statement
>
> Since I don't do this that often I usually Google on how to call the various methods of Microsoft.Office.Interop.Excel.
>
> Jim Kinneman
> Senior Consultant
> Encompass Solutions
>
> --- In vantage@yahoogroups.com, "dgodfrey_amc" <dgodfrey_amc@> wrote:
> >
> > I am trying to read and write to an excel file through the Customization editor. I am using an OleDbConnection. I am able to read from the excel file this way but I can not write to a file. Does anyone have any examples of how to write back a dataset or even just a row using OleDbConnection OR
> >
> > does anyone have a better way to do this I would really appreciate it.
> >
>