30-11-15, 04:24 PM
اخي hamada558
الكود حقك ظبط بس فية مشكلتين مش بيسكر الاكسيل لو سكرت الفورم وكمان بيظهر رسالة الخفظ حق الاكسيل
بس مشكلة واحدة فقط لو مسطب نسخة اوفيس مش مفعلة بيظهر رسالة طلب التفعيل للاكسيل فية طريقة تتلغي ؟
هذا الكود الي ظبط معي حبيت اضيفة ممكن حد يستفيد منة ممكن فية اخطاء بس ظبط معايا
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form2
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'~~> Opens Source Workbook. Change path and filename as applicable
xlWorkBook = xlApp.Workbooks.Open("C:\test.xlsx")
'~~> Display Excel
xlApp.Visible = False
'~~> Set the source worksheet
xlWorkSheet = xlWorkBook.Sheets("sheets1")
Dim Sa = TextBox1.Text
xlWorkSheet.PrintOut(From:=1, To:=7, Copies:=Sa, Collate:=True)
xlWorkSheet = Nothing
xlWorkBook.Save()
Try
Catch ex As Exception
' Respond to the error.
Finally
' Close the workbook object.
If Not xlWorkBook Is Nothing Then
xlWorkBook.Close(False)
xlWorkBook = Nothing
End If
' Quit Excel and release the ApplicationClass object.
If Not xlApp Is Nothing Then
xlApp.Quit()
xlApp = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
الكود حقك ظبط بس فية مشكلتين مش بيسكر الاكسيل لو سكرت الفورم وكمان بيظهر رسالة الخفظ حق الاكسيل
بس مشكلة واحدة فقط لو مسطب نسخة اوفيس مش مفعلة بيظهر رسالة طلب التفعيل للاكسيل فية طريقة تتلغي ؟
هذا الكود الي ظبط معي حبيت اضيفة ممكن حد يستفيد منة ممكن فية اخطاء بس ظبط معايا
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form2
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'~~> Opens Source Workbook. Change path and filename as applicable
xlWorkBook = xlApp.Workbooks.Open("C:\test.xlsx")
'~~> Display Excel
xlApp.Visible = False
'~~> Set the source worksheet
xlWorkSheet = xlWorkBook.Sheets("sheets1")
Dim Sa = TextBox1.Text
xlWorkSheet.PrintOut(From:=1, To:=7, Copies:=Sa, Collate:=True)
xlWorkSheet = Nothing
xlWorkBook.Save()
Try
Catch ex As Exception
' Respond to the error.
Finally
' Close the workbook object.
If Not xlWorkBook Is Nothing Then
xlWorkBook.Close(False)
xlWorkBook = Nothing
End If
' Quit Excel and release the ApplicationClass object.
If Not xlApp Is Nothing Then
xlApp.Quit()
xlApp = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Try

