Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP.NET > ASP.NET Word.Application > ASP.NET & Word (Word Application) - Word Document Sample Report



Clound SSD Virtual Server

ASP.NET & Word (Word Application) - Word Document Sample Report

ASP.NET & Word (Word.Application) - Word Document Sample Report ตัวอย่างนี้จะเป็นการเขียน ASP.NET กับ Word ในรูปแบบของรายงาน

ASP.NET Config Word (Word Application)


Framework 1.1,2.0,3.0,4.0

Word Document for C# อ่านและดัดแปลงได้จากบทความนี้


Sample

Imports Microsoft.Office.Interop.Word
Imports System.Data
Imports System.Data.OleDb
Public Class AspNetWordReport
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Const wdAlignParagraphCenter = 1
        Const wdAlignParagraphRight = 2

        Dim Wrd As New Microsoft.Office.Interop.Word.Application
        Dim WrdDoc As Microsoft.Office.Interop.Word.Document
        Dim MyRange1, MyRange2, MyRange3 As Microsoft.Office.Interop.Word.Range
        Dim objTable As Microsoft.Office.Interop.Word.Table
        Dim DocName As String = "MyDoc/MyWord.doc"
        Dim intRows As Integer
        Wrd.Application.Visible = False

        WrdDoc = Wrd.Documents.Open(Server.MapPath("thaicreate.dot"))

        MyRange1 = WrdDoc.Paragraphs.Add.Range
        With MyRange1
            .ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Font.Name = "Verdana"
            .Font.Size = "20"
            .Font.Bold = True
            .InsertBefore("Customer Report" & vbCrLf)
        End With

        '*** DataTable ***'
        Dim objConn As OleDbConnection
        Dim objCmd As OleDbCommand
        Dim dtAdapter As OleDbDataAdapter
        Dim dt As New DataTable
        Dim strConnString As String
        strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/mydatabase.mdb") & ";Jet OLEDB:Database Password=;"
        objConn = New OleDbConnection(strConnString)
        objConn.Open()

        Dim strSQL As String
        strSQL = "SELECT * FROM customer"
        dtAdapter = New OleDbDataAdapter(strSQL, objConn)
        dtAdapter.Fill(dt)
        dtAdapter = Nothing
        objConn.Close()
        objConn = Nothing
        '*** (End) DataTable ***'

        MyRange2 = WrdDoc.Paragraphs.Add.Range
        With MyRange2
            .Font.Size = "10"
        End With
        objTable = Wrd.ActiveDocument.Tables.Add(MyRange2, dt.Rows.Count, 6, 1, 2) '** Range,Rows,Column **'

        '*** Header ***'
        objTable.Cell(1, 1).Range.InsertAfter("CustomerID")
        objTable.Cell(1, 1).Range.Bold = True
        objTable.Cell(1, 1).Range.ParagraphFormat.Alignment = 1

        objTable.Cell(1, 2).Range.InsertAfter("Name")
        objTable.Cell(1, 2).Range.Bold = True
        objTable.Cell(1, 2).Range.ParagraphFormat.Alignment = 1

        objTable.Cell(1, 3).Range.InsertAfter("Email")
        objTable.Cell(1, 3).Range.Bold = True
        objTable.Cell(1, 3).Range.ParagraphFormat.Alignment = 1

        objTable.Cell(1, 4).Range.InsertAfter("CountryCode")
        objTable.Cell(1, 4).Range.Bold = True
        objTable.Cell(1, 4).Range.ParagraphFormat.Alignment = 1

        objTable.Cell(1, 5).Range.InsertAfter("Budget")
        objTable.Cell(1, 5).Range.Bold = True
        objTable.Cell(1, 5).Range.ParagraphFormat.Alignment = 1

        objTable.Cell(1, 6).Range.InsertAfter("Used")
        objTable.Cell(1, 6).Range.Bold = True
        objTable.Cell(1, 6).Range.ParagraphFormat.Alignment = 1

        '*** Detail ***
        For intRows = 0 To dt.Rows.Count - 1
            objTable.Cell(intRows + 2, 1).Range.InsertAfter(dt.Rows(intRows)("CustomerID"))
            objTable.Cell(intRows + 2, 1).Range.ParagraphFormat.Alignment = 1

            objTable.Cell(intRows + 2, 2).Range.InsertAfter(dt.Rows(intRows)("Name"))
            objTable.Cell(intRows + 2, 2).Range.ParagraphFormat.Alignment = 0

            objTable.Cell(intRows + 2, 3).Range.InsertAfter(dt.Rows(intRows)("Email"))
            objTable.Cell(intRows + 2, 3).Range.ParagraphFormat.Alignment = 0

            objTable.Cell(intRows + 2, 4).Range.InsertAfter(dt.Rows(intRows)("CountryCode"))
            objTable.Cell(intRows + 2, 4).Range.ParagraphFormat.Alignment = 1

            objTable.Cell(intRows + 2, 5).Range.InsertAfter(FormatNumber(dt.Rows(intRows)("Budget"), 2))
            objTable.Cell(intRows + 2, 5).Range.ParagraphFormat.Alignment = 2

            objTable.Cell(intRows + 2, 6).Range.InsertAfter(FormatNumber(dt.Rows(intRows)("Used"), 2))
            objTable.Cell(intRows + 2, 6).Range.ParagraphFormat.Alignment = 2
        Next


        MyRange3 = WrdDoc.Paragraphs.Add.Range
        With MyRange3
            .ParagraphFormat.Alignment = wdAlignParagraphRight
            .Font.Name = "Verdana"
            .Font.Size = "10"
            .InsertBefore(vbCrLf & vbCrLf & vbCrLf & "................................Manager" & vbCrLf & Now())
        End With

        WrdDoc.SaveAs(Server.MapPath(DocName))
        Wrd.Application.Quit()
        Wrd = Nothing       
    End Sub
End Class


Screenshot

ASP.NET & Word


ดาวน์โหลด Source Code ทั้งหมดได้ในส่วนของดาวน์โหลด






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-26 21:05:09 / 2011-09-08 22:41:54
  Download : Download  ASP.NET & Word (Word Application) - Word Document Sample Report
 Sponsored Links / Related

 
ASP.NET Word Response.ContentType = "application/vnd.ms-word"
Rating :

 
ASP.NET Config Word (Word Application)
Rating :

 
ASP.NET Connect to Word Application
Rating :

 
ASP.NET & Word (Word Application) - Create Word Document
Rating :

 
ASP.NET & Word (Word Application) - Page Setup
Rating :

 
ASP.NET & Word (Word Application) - BuiltInDocumentProperties
Rating :

 
ASP.NET & Word (Word Application) - Font & Style
Rating :

 
ASP.NET & Word (Word Application) - Paragraphs & Range
Rating :

 
ASP.NET & Word (Word Application) - Page Breaking
Rating :

 
ASP.NET & Word (Word Application) - Create/Insert Table (Tables.Add)
Rating :

 
ASP.NET & Word (Word Application) - Add/Insert Picture (AddPicture)
Rating :

 
ASP.NET & Word (Word Application) - Open Document (Documents.Open)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่