تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيف اطبع من الاكسيل
#9
سبق أن خبرتك مالي في هذا المجال منشان هيك خبرت صديق لي بيعرف VB وأرسلت له طلبك مع رابط مساعد
فعملك تشكيلة دوال التعامل مع ملف الاكسل إن شاء الله بتعجبك وتلبي متطلبات مشروعك

1: طباعة مجال محدد من شيت معين من ملف اكسل PrintExcelSheetRange

2: تحويل مجال محدد من شيت معين من ملف اكسل إلى بي دي اف ExportExcelRangeToPdf

3: تحويل شيت معين من ملف اكسل إلى بي دي اف ExportExcelSheetToPdf

4: تحويل كامل ملف اكسل إلى بي دي اف ExportExcelWorkbookToPdf

PrintExcelSheetRange
كود :
   ''' <summary>طباعة مجال محدد من شيت معين من ملف اكسل</summary>
   ''' <param name="excelFile">إسم ملف الاكسل</param>
   ''' <param name="sheetName">إسم الشيت</param>
   ''' <param name="rangeAddress">A1:G50 عنوان المجال مثل</param>
   ''' <param name="copies">إختياري: عدد نسخ الطباعة</param>
   Shared Sub PrintExcelSheetRange(ByVal excelFile As String, ByVal sheetName As String, ByVal rangeAddress As String, Optional ByVal copies As Integer = 1)
       If Not IO.File.Exists(excelFile) Then
           MsgBox("لم أجد ملف الاكسل بإسم" & vbCrLf & excelFile)
           Return
       End If
       Dim excelApplication As New Excel.Application
       Dim excelWorkbook As Excel.Workbook = Nothing
       Dim excelSheet As Excel.Worksheet = Nothing
       Try

           excelApplication.Visible = False
           excelWorkbook = excelApplication.Workbooks.Open(excelFile)
           excelSheet = excelWorkbook.Sheets(sheetName)

           excelSheet.PageSetup.PrintArea = rangeAddress
           excelSheet.PrintOut(From:=1, To:=7, Copies:=copies, Collate:=True)


       Catch ex As Exception
           ' Respond to the error.
       End Try

       ' Close the workbook object.
       If Not excelWorkbook Is Nothing Then
           excelWorkbook.Close(False)
           excelWorkbook = Nothing
       End If

       ' Quit Excel and release the ApplicationClass object.
       If Not excelApplication Is Nothing Then
           excelApplication.Quit()
           excelApplication = Nothing
       End If

       GC.Collect()
       GC.WaitForPendingFinalizers()
   End Sub

ExportExcelRangeToPdf
كود :
''' <summary>تحويل مجال محدد من شيت معين من ملف اكسل إلى بي دي اف</summary>
    ''' <param name="excelFile">إسم ملف الاكسل</param>
    ''' <param name="sheetName">إسم الشيت</param>
    ''' <param name="rangeAddress">A1:G50 عنوان المجال مثل</param>
    ''' <param name="pdtFile">إسم ملف بي دي اف</param>
    Shared Sub ExportExcelRangeToPdf(ByVal excelFile As String, ByVal sheetName As String, ByVal rangeAddress As String, ByVal pdtFile As String)
        If Not IO.File.Exists(excelFile) Then
            MsgBox("لم أجد ملف الاكسل بإسم" & vbCrLf & excelFile)
            Return
        End If
        Dim excelApplication As New Excel.Application
        Dim excelWorkbook As Excel.Workbook = Nothing
        Dim excelSheet As Excel.Worksheet = Nothing
        Dim excelRange As Excel.Range = Nothing
        Try

            ' Open the source workbook.
            excelWorkbook = excelApplication.Workbooks.Open(excelFile)

            If excelWorkbook.Sheets.Cast(Of Object).Any(Function(x) x.Name.Equals(sheetName)) Then

                excelSheet = excelWorkbook.Sheets(sheetName)

                Dim paramExportFormat As Excel.XlFixedFormatType = Excel.XlFixedFormatType.xlTypePDF
                Dim paramExportQuality As Excel.XlFixedFormatQuality = Excel.XlFixedFormatQuality.xlQualityStandard
                Dim paramOpenAfterPublish As Boolean = False
                Dim paramIncludeDocProps As Boolean = True
                Dim paramIgnorePrintAreas As Boolean = True
                Dim paramFromPage As Object = Type.Missing
                Dim paramToPage As Object = Type.Missing

                excelRange = excelSheet.Range(rangeAddress)

                ' Save it in the target format.
                If Not excelRange Is Nothing Then
                    excelRange.ExportAsFixedFormat(
                        paramExportFormat, _
                        pdtFile, paramExportQuality, _
                        paramIncludeDocProps, paramIgnorePrintAreas, _
                        paramFromPage, paramToPage, paramOpenAfterPublish)
                End If
            Else
                MsgBox("لم أجد شيت بإسم" & vbCrLf & sheetName)
            End If
        Catch ex As Exception
            ' Respond to the error.
        End Try

        ' Close the workbook object.
        If Not excelWorkbook Is Nothing Then
            excelWorkbook.Close(False)
            excelWorkbook = Nothing
        End If

        ' Quit Excel and release the ApplicationClass object.
        If Not excelApplication Is Nothing Then
            excelApplication.Quit()
            excelApplication = Nothing
        End If

        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub

ExportExcelSheetToPdf
كود :
''' <summary>تحويل شيت معين من ملف اكسل إلى بي دي اف</summary>
    ''' <param name="excelFile">إسم ملف الاكسل</param>
    ''' <param name="sheetName">إسم الشيت</param>
    ''' <param name="pdtFile">إسم ملف بي دي اف</param>
    Shared Sub ExportExcelSheetToPdf(ByVal excelFile As String, ByVal sheetName As String, ByVal pdtFile As String)
        If Not IO.File.Exists(excelFile) Then
            MsgBox("لم أجد ملف الاكسل بإسم" & vbCrLf & excelFile)
            Return
        End If
        Dim excelApplication As New Excel.Application
        Dim excelWorkbook As Excel.Workbook = Nothing
        Dim excelSheet As Excel.Worksheet = Nothing
        Try

            ' Open the source workbook.
            excelWorkbook = excelApplication.Workbooks.Open(excelFile)

            If excelWorkbook.Sheets.Cast(Of Object).Any(Function(x) x.Name.Equals(sheetName)) Then

                excelSheet = excelWorkbook.Sheets(sheetName)

                Dim paramExportFormat As Excel.XlFixedFormatType = Excel.XlFixedFormatType.xlTypePDF
                Dim paramExportQuality As Excel.XlFixedFormatQuality = Excel.XlFixedFormatQuality.xlQualityStandard
                Dim paramOpenAfterPublish As Boolean = False
                Dim paramIncludeDocProps As Boolean = True
                Dim paramIgnorePrintAreas As Boolean = True
                Dim paramFromPage As Object = Type.Missing
                Dim paramToPage As Object = Type.Missing

                ' Save it in the target format.
                If Not excelSheet Is Nothing Then
                    excelSheet.ExportAsFixedFormat(
                        paramExportFormat, _
                        pdtFile, paramExportQuality, _
                        paramIncludeDocProps, paramIgnorePrintAreas, _
                        paramFromPage, paramToPage, paramOpenAfterPublish)
                End If
            Else
                MsgBox("لم أجد شيت بإسم" & vbCrLf & sheetName)
            End If
        Catch ex As Exception
            ' Respond to the error.
        End Try

        ' Close the workbook object.
        If Not excelWorkbook Is Nothing Then
            excelWorkbook.Close(False)
            excelWorkbook = Nothing
        End If

        ' Quit Excel and release the ApplicationClass object.
        If Not excelApplication Is Nothing Then
            excelApplication.Quit()
            excelApplication = Nothing
        End If

        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub

ExportExcelWorkbookToPdf
كود :
''' <summary>تحويل كامل ملف اكسل إلى بي دي اف</summary>
    ''' <param name="excelFile">إسم ملف الاكسل</param>
    ''' <param name="pdtFile">إسم ملف بي دي اف</param>
    Shared Sub ExportExcelWorkbookToPdf(ByVal excelFile As String, ByVal pdtFile As String)
        If Not IO.File.Exists(excelFile) Then
            MsgBox("لم أجد ملف الاكسل بإسم" & vbCrLf & excelFile)
            Return
        End If
        Dim excelApplication As New Excel.Application
        Dim excelWorkbook As Excel.Workbook = Nothing
        Try

            Dim paramExportFormat As Excel.XlFixedFormatType = Excel.XlFixedFormatType.xlTypePDF
            Dim paramExportQuality As Excel.XlFixedFormatQuality = Excel.XlFixedFormatQuality.xlQualityStandard
            Dim paramOpenAfterPublish As Boolean = False
            Dim paramIncludeDocProps As Boolean = True
            Dim paramIgnorePrintAreas As Boolean = True
            Dim paramFromPage As Object = Type.Missing
            Dim paramToPage As Object = Type.Missing

            ' Open the source workbook.
            excelWorkbook = excelApplication.Workbooks.Open(excelFile)

            ' Save it in the target format.
            If Not excelWorkbook Is Nothing Then
                excelWorkbook.ExportAsFixedFormat(
                    paramExportFormat, _
                    pdtFile, paramExportQuality, _
                    paramIncludeDocProps, paramIgnorePrintAreas, _
                    paramFromPage, paramToPage, paramOpenAfterPublish)
            End If

        Catch ex As Exception
            ' Respond to the error.
        End Try

        ' Close the workbook object.
        If Not excelWorkbook Is Nothing Then
            excelWorkbook.Close(False)
            excelWorkbook = Nothing
        End If

        ' Quit Excel and release the ApplicationClass object.
        If Not excelApplication Is Nothing Then
            excelApplication.Quit()
            excelApplication = Nothing
        End If

        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
الرد }}}
تم الشكر بواسطة: salahalmasry


الردود في هذا الموضوع
كيف اطبع من الاكسيل - بواسطة salahalmasry - 29-11-15, 05:14 PM
RE: كيف اطبع من الاكسيل - بواسطة hamada558 - 29-11-15, 05:47 PM
RE: كيف اطبع من الاكسيل - بواسطة salahalmasry - 29-11-15, 06:38 PM
RE: كيف اطبع من الاكسيل - بواسطة hamada558 - 29-11-15, 07:34 PM
RE: كيف اطبع من الاكسيل - بواسطة salahalmasry - 29-11-15, 11:26 PM
RE: كيف اطبع من الاكسيل - بواسطة hamada558 - 30-11-15, 01:43 AM
RE: كيف اطبع من الاكسيل - بواسطة salahalmasry - 30-11-15, 10:41 AM
RE: كيف اطبع من الاكسيل - بواسطة salahalmasry - 30-11-15, 04:24 PM
RE: كيف اطبع من الاكسيل - بواسطة hamada558 - 01-12-15, 08:24 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] كود استيراد الاصناف من البرنامج الى الاكسيل Hamza8484 12 862 30-07-24, 10:20 AM
آخر رد: تركي الحلواني
  اظهار اسماء الورقات في ملف الاكسيل المتألق9 1 1,107 14-12-21, 01:18 AM
آخر رد: ابراهيم ايبو
  لم اجد مكتبة الاكسيل في المراجع داخل الفيجوال بيسك 2019 Alanwalker 2 1,712 05-06-21, 08:27 PM
آخر رد: Alanwalker
  [سؤال] مشكلة عرض بيانات الاكسيل في الكريستال الريبورت i1982 3 2,067 07-09-20, 12:24 PM
آخر رد: Hasaneen
  [VB.NET] الاكسيل والفيجول بيسك محمد اسماعيل 0 1,548 31-10-18, 11:10 AM
آخر رد: محمد اسماعيل
  [VB.NET] المخططات البيانية داخل الاكسيل محمد اسماعيل 0 1,518 15-10-18, 03:57 AM
آخر رد: محمد اسماعيل
  المساعدة في كود تصدير الجدول الي الاكسيل khaled12345 10 5,293 26-11-17, 05:50 PM
آخر رد: khaled12345
  تصديراعمده DataGridView الى الاكسيل الدريساوي 7 5,951 16-10-17, 02:20 AM
آخر رد: hoshosgost@yahoo.com
  ايه فايدة التقاير لما ممكن اطبع الفورم ؟؟؟ نبيل كونكت 1 1,472 22-08-17, 11:59 AM
آخر رد: حريف برمجة
  كيفية تحويل الماكرو اللي في الاكسيل الي برنامج فيجوال بيسك khaled12345 2 2,346 22-06-17, 03:48 AM
آخر رد: khaled12345

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم