كيف اطبع من الاكسيل - salahalmasry - 29-11-15
السلام عليكم ورحمة الله وبركاتة
هل يوجد طريقة اني اقومم بعمل طباعة لعدد معين من الصفحات من ملف اكسيل عن طريق برنامج اخر دون الحاجة لفتح الاكسيل وحتى دون الحاجة لعرض الملف الاكسيل
مثلا عندي برنامج بدخل منة قيم لخلايا معينة لملف اكسيل واطبع منة صفحات معينة بالتنسيق والصور وكل شيء هل هذا ممكن ؟؟
RE: كيف اطبع من الاكسيل - hamada558 - 29-11-15
هاد الرابط بيتكم عن نفس طلبك، ومن حظك انه VB
http://www.siddharthrout.com/2012/09/12/printing-excel-sheetworkbook
RE: كيف اطبع من الاكسيل - salahalmasry - 29-11-15
شكرا لك اخي hamada558
سؤال كمان
لو عاوز بدل الطباعة يتصدر نطاق معين من الاكسيل على ملف بصيغة ( pdf ) في مجلد ثابت يكون في برتيشن C
RE: كيف اطبع من الاكسيل - hamada558 - 29-11-15
هاد الرابط ايضا بيتكلم عن حفظ pdf من ميكروسوفت
https://msdn.microsoft.com/en-us/library/bb407651(v=office.12).aspx?cs-save-lang=1&cs-lang=vb
بتشكرك على التقييم عزيزي
RE: كيف اطبع من الاكسيل - salahalmasry - 29-11-15
لية تشكرني ردك كان سريع وكمان حصلتلي طلبي بالظبط يعني انا الي اشكرك
بس فية مشكلة التجربة نجحت بس الاكسيل بيكون مفتوح في التاسك مانيجر والملف بيكون مفعل حاولت اكتب الكود دة
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
RE: كيف اطبع من الاكسيل - hamada558 - 30-11-15
ولو ان الكود 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
RE: كيف اطبع من الاكسيل - salahalmasry - 30-11-15
تسلم والله جاري التجربة بعد انتهاء الدوام
RE: كيف اطبع من الاكسيل - salahalmasry - 30-11-15
اخي 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
RE: كيف اطبع من الاكسيل - hamada558 - 01-12-15
سبق أن خبرتك مالي في هذا المجال منشان هيك خبرت صديق لي بيعرف 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
|