تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيف اطبع من الاكسيل
#1
السلام عليكم ورحمة الله وبركاتة 

هل يوجد طريقة اني اقومم بعمل طباعة لعدد معين من الصفحات من ملف اكسيل عن طريق برنامج اخر دون الحاجة لفتح الاكسيل وحتى دون الحاجة لعرض الملف الاكسيل

مثلا عندي برنامج بدخل منة قيم لخلايا معينة لملف اكسيل واطبع منة صفحات معينة بالتنسيق والصور وكل شيء  هل هذا ممكن ؟؟
الرد }}}
تم الشكر بواسطة:
#2
هاد الرابط بيتكم عن نفس طلبك، ومن حظك انه VB
http://www.siddharthrout.com/2012/09/12/...etworkbook
الرد }}}
تم الشكر بواسطة: salahalmasry
#3
شكرا لك اخي hamada558

سؤال كمان
لو عاوز بدل الطباعة يتصدر نطاق معين من الاكسيل على ملف بصيغة ( pdf ) في مجلد ثابت يكون في برتيشن C
الرد }}}
تم الشكر بواسطة:
#4
هاد الرابط ايضا بيتكلم عن حفظ pdf من ميكروسوفت
https://msdn.microsoft.com/en-us/library...cs-lang=vb

بتشكرك على التقييم عزيزي
الرد }}}
تم الشكر بواسطة: salahalmasry
#5
لية تشكرني ردك كان سريع وكمان حصلتلي طلبي بالظبط يعني انا الي اشكرك

بس فية مشكلة التجربة نجحت بس الاكسيل بيكون مفتوح في التاسك مانيجر والملف بيكون مفعل حاولت اكتب الكود دة
xlWorkSheet = Nothing
xlWorkBook.Save()
xlApp.Quit()
بس مظبطش هكتب الكود الي اشتغل كلة لو حد عندة حل ياريت يفيدني

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:\Print.xlsx")

'~~> Display Excel
xlApp.Visible = False

'~~> Set the source worksheet
xlWorkSheet = xlWorkBook.Sheets("sheets")
Dim Sa = TextBox1.Text
'~~> Printing the Excel Sheet
xlWorkSheet.PrintOut(From:=1, To:=7, Copies:=Sa, Collate:=True)
xlWorkSheet = Nothing
xlWorkBook.Save()
xlApp.Quit()

End Sub




End Class
الرد }}}
تم الشكر بواسطة:
#6
ولو ان الكود VB وليس CS لكن منشان خطرك عدلتلك اياه
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xlApp As New Excel.Application
        Try
            Dim xlWorkBook As Excel.Workbook
            Dim xlWorkSheet As Excel.Worksheet

            '~~> Opens Source Workbook. Change path and filename as applicable
            xlWorkBook = xlApp.Workbooks.Open("C:\Print.xlsx")

            '~~> Display Excel
            xlApp.Visible = False

            '~~> Set the source worksheet
            xlWorkSheet = xlWorkBook.Sheets("sheets")
            Dim Sa = TextBox1.Text
            '~~> Printing the Excel Sheet
            xlWorkSheet.PrintOut(From:=1, To:=7, Copies:=Sa, Collate:=True)
            xlWorkSheet = Nothing
            xlWorkBook = Nothing  ' غيرته

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        xlApp.Quit()
        xlApp = Nothing ' زيادة - هاد مهم منشان الامر التالي

        GC.Collect() '  زيادة - وهاد هو المهم منشان يحذفه من التاسك بعد ما ينهي مهمته
    End Sub
الرد }}}
تم الشكر بواسطة: salahalmasry
#7
تسلم والله جاري التجربة بعد انتهاء الدوام
الرد }}}
تم الشكر بواسطة:
#8
اخي 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
الرد }}}
تم الشكر بواسطة: hamada558
#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


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  اظهار اسماء الورقات في ملف الاكسيل المتألق9 1 896 14-12-21, 01:18 AM
آخر رد: ابراهيم ايبو
  لم اجد مكتبة الاكسيل في المراجع داخل الفيجوال بيسك 2019 Alanwalker 2 1,396 05-06-21, 08:27 PM
آخر رد: Alanwalker
  [سؤال] مشكلة عرض بيانات الاكسيل في الكريستال الريبورت i1982 3 1,652 07-09-20, 12:24 PM
آخر رد: Hasaneen
  [VB.NET] الاكسيل والفيجول بيسك محمد اسماعيل 0 1,403 31-10-18, 11:10 AM
آخر رد: محمد اسماعيل
  [VB.NET] المخططات البيانية داخل الاكسيل محمد اسماعيل 0 1,382 15-10-18, 03:57 AM
آخر رد: محمد اسماعيل
  المساعدة في كود تصدير الجدول الي الاكسيل khaled12345 10 4,782 26-11-17, 05:50 PM
آخر رد: khaled12345
  تصديراعمده DataGridView الى الاكسيل الدريساوي 7 5,530 16-10-17, 02:20 AM
آخر رد: hoshosgost@yahoo.com
  ايه فايدة التقاير لما ممكن اطبع الفورم ؟؟؟ نبيل كونكت 1 1,284 22-08-17, 11:59 AM
آخر رد: حريف برمجة
  كيفية تحويل الماكرو اللي في الاكسيل الي برنامج فيجوال بيسك khaled12345 2 2,155 22-06-17, 03:48 AM
آخر رد: khaled12345
  تصدير المعلمومات الي الاكسيل khaled12345 10 4,650 07-06-17, 03:55 AM
آخر رد: khaled12345

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


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