For i = 1 To 10000
frmShowProgress.ProgressBar1.Value = i
If i = frmShowProgress.ProgressBar1.Maximum / 2 Then
If a = 6 Then
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim datestr As String = Now.ToString("yyyyMMddHmmss")
Dim tmpRpt As String = System.Windows.Forms.Application.StartupPath & "\ReportTmp\Qry\tmpQry.xls"
Dim newRpr As String = tmpRpt
xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open(newRpr) 'เปิดรายงาน
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
Dim countCol As Integer = DgvAllSupport.ColumnCount
Dim countRow As Integer = DgvAllSupport.RowCount
xlWorkSheet.Range("A2").Value = "ลำดับ"
'เพิ่ม เส้นขอบในเซลล์
xlWorkSheet.Range("A2").Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range("A2").Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range("A2").Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range("A2").Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlBorderWeight.xlHairline
dlg_ProgressTo7.Show()
dlg_ProgressTo7.ProgressBar1.Value = 0
dlg_ProgressTo7.ProgressBar1.Maximum = countRow
dlg_ProgressTo7.txtStatus.Text = "กำลังใส่ลำดับ"
For CountNo = 1 To countRow
xlWorkSheet.Range("A" & CountNo + 2).Value = CountNo
'เพิ่ม เส้นขอบในเซลล์
xlWorkSheet.Range("A" & CountNo + 2).Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range("A" & CountNo + 2).Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range("A" & CountNo + 2).Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range("A" & CountNo + 2).Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlBorderWeight.xlHairline
dlg_ProgressTo7.ProgressBar1.Value = CountNo
dlg_ProgressTo7.Refresh()
Next CountNo
dlg_ProgressTo7.ProgressBar1.Value = 0
dlg_ProgressTo7.ProgressBar1.Maximum = countCol
For coli = 1 To countCol
Dim colname As String
colname = Choose(coli, "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BM", "BN", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY")
xlWorkSheet.Range("A1").Value = Me.Text
xlWorkSheet.Range(colname & 2).Value = DgvAllSupport.Columns.Item(coli - 1).HeaderText
'เพิ่ม เส้นขอบในเซลล์
xlWorkSheet.Range(colname & 2).Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range(colname & 2).Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range(colname & 2).Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range(colname & 2).Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlBorderWeight.xlHairline
For rowi = 0 To countRow
Try
xlWorkSheet.Range(colname & rowi + 2).Value = DgvAllSupport.Rows(rowi - 1).Cells(coli - 1).Value.ToString
'เพิ่ม เส้นขอบในเซลล์
xlWorkSheet.Range(colname & rowi + 2).Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range(colname & rowi + 2).Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range(colname & rowi + 2).Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlBorderWeight.xlHairline
xlWorkSheet.Range(colname & rowi + 2).Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlBorderWeight.xlHairline
Catch ex As Exception
'MsgBox(ex.Message)
End Try
dlg_ProgressTo7.txtStatus.Text = "กำลัง Export ข้อมูล (คอลัมน์ที่ " & coli & " / " & countCol & " แถวที่ " & rowi & " / " & countRow & ")"
Next rowi
dlg_ProgressTo7.ProgressBar1.Value = coli
Next coli
MessageBox.Show("ทำการ Copy ข้อมูลทั้งหมดไปยังไฟล์ Excel เรียบร้อยแล้ว", "การทำงานเสร็จสิ้น", MessageBoxButtons.OK, MessageBoxIcon.Information)
xlApp.Visible = True
End If
End If
Next
Tag : .NET, Excel (Excel.Application), VB.NET, Windows
Date :
2014-09-05 09:14:06
By :
zarooman
View :
1955
Reply :
13
No. 1
Guest
Code (VB.NET)
'System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim datestr As String = Now.ToString("yyyyMMddHmmss", New System.Globalization.CultureInfo("en-US")) '<-- แก้
เครื่อง User หลายเครื่องครับ บางเครื่องฟอร์แมตไม่เหมือนกันอะครับ เลยต้องเปลี่ยน กันเหนียวไว้
ส่วน Dim datestr As String = Now.ToString("yyyyMMddHmmss") จะเป็นรูปแบบการตั้งค่าที่เราเปลี่ยนด้านบนไม่ใช่หรอครับ
ทดสอบความทรงจำASP.NET Repeater ข้อมูลมันจะหายไปเมื่อ PostBack (Item.DataItem IS NULL)
Code (VB.NET)
Private Sub rtorABC_ItemCreated(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rtorABC.ItemCreated
'*****Fixed Bug's Item.DataItem ARE ALL NULL When PostBack.*******
If ((e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem)) Then
Dim txtPart_NO As HtmlInputText = DirectCast(e.Item.FindControl("txtPart_NO"), HtmlInputText)
If txtPart_NO IsNot Nothing Then
txtPart_NO.Attributes.Add("Hacks", "อะไรก็ได้")
End If
End If
End Sub