2008年12月25日 星期四

努力多時的案子飛了

真氣人,努力了一個多月的案子飛了

唉。。。。景氣真的有這麼壞嗎?

搶搶搶,他媽的搶屁呀

真的是黑馬還是官商勾結?

讓我忙的機會少了一個

殘念

現在連敲門磚都飛了

拿啥敲門

意思是我的修煉還不夠嗎?

這種小案子也要搶。。。。

更氣人的是

我們竟然會輸

馬的

丟人

氣人

唉。。。。。

加薪又很遠了....

2008年12月11日 星期四

vb.net 動態call form

 Private Sub ShowForm(ByVal FormName As String)
        Dim ProjectName As String =
        Reflection.Assembly.GetExecutingAssembly.GetName.Name
        Try
            Dim tyOfStringVariable As Type = Type.GetType(ProjectName & "." &
            FormName)
            Dim frmObject As Object = Activator.CreateInstance(tyOfStringVariable)
            DirectCast(frmObject, Form).StartPosition =
            FormStartPosition.CenterParent
            DirectCast(frmObject, Form).ShowDialog()
        Catch ex As Exception
            ' TODO
        End Try
    End Sub

2008年12月2日 星期二

vb.net ->word

Public Class WordOpLib
Private oWordApplic As Word.Application
Private oDocument As Word.Document
Private oRange As Word.Range
Private oSelection As Word.Selection
Public Sub New()
'啟動com word介面
oWordApplic = New Word.Application
oWordApplic.Visible = True
End Sub
'設置選定文本
Public Sub SetRange(ByVal para As Integer)
oRange = oDocument.Paragraphs(para).Range
oRange.Select()
End Sub
Public Sub SetRange(ByVal para As Integer, ByVal sent As Integer)
oRange = oDocument.Paragraphs(para).Range.Sentences(sent)
oRange.Select()
End Sub
Public Sub SetRange(ByVal startpoint As Integer, ByVal endpoint As Integer, ByVal flag As Boolean)
If flag = True Then
oRange = oDocument.Range(startpoint, endpoint)
oRange.Select()
Else

End If
End Sub

'生成空的新文檔
Public Sub NewDocument()
Dim missing = System.Reflection.Missing.Value
Dim isVisible As Boolean = True
oDocument = oWordApplic.Documents.Add(missing, missing, missing, missing)
oDocument.Activate()
End Sub
'使用範本生成新文檔
Public Sub NewDocWithModel(ByVal FileName As String)
Dim missing = System.Reflection.Missing.Value
Dim isVisible As Boolean = True
Dim strName As String
strName = FileName

oDocument = oWordApplic.Documents.Add(strName, missing, missing, isVisible)
oDocument.Activate()
End Sub
'打開已有文檔
Public Sub OpenFile(ByVal FileName As String)
Dim strName As String
Dim isReadOnly As Boolean
Dim isVisible As Boolean
Dim missing = System.Reflection.Missing.Value

strName = FileName
isReadOnly = False
isVisible = True

oDocument = oWordApplic.Documents.Open(strName, missing, isReadOnly, missing, missing, missing, missing, missing, missing, missing, missing, isVisible, missing, missing, missing, missing)
oDocument.Activate()

End Sub
Public Sub OpenFile(ByVal FileName As String, ByVal isReadOnly As Boolean)
Dim strName As String
Dim isVisible As Boolean
Dim missing = System.Reflection.Missing.Value

strName = FileName
isVisible = True

oDocument = oWordApplic.Documents.Open(strName, missing, isReadOnly, missing, missing, missing, missing, missing, missing, missing, missing, isVisible, missing, missing, missing, missing)
oDocument.Activate()
End Sub
'退出Word
Public Sub Quit()
Dim missing = System.Reflection.Missing.Value
oWordApplic.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordApplic)
oWordApplic = Nothing
End Sub
'關閉所有打開的文檔
Public Sub CloseAllDocuments()
oWordApplic.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
End Sub
'關閉當前的文檔
Public Sub CloseCurrentDocument()
oDocument.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
End Sub
'保存當前文檔
Public Sub Save()
Try
oDocument.Save()
Catch
MsgBox(Err.Description)
End Try
End Sub
'另存為文檔
Public Sub SaveAs(ByVal FileName As String)
Dim strName As String
Dim missing = System.Reflection.Missing.Value

strName = FileName

oDocument.SaveAs(strName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
End Sub
'保存為Html檔
Public Sub SaveAsHtml(ByVal FileName As String)
Dim missing = System.Reflection.Missing.Value
Dim strName As String

strName = FileName
Dim format = CInt(Word.WdSaveFormat.wdFormatHTML)

oDocument.SaveAs(strName, format, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
End Sub
'插入文本
Public Sub InsertText(ByVal text As String)
oWordApplic.Selection.TypeText(text)
End Sub
'插入一個空行
Public Sub InsertLineBreak()
oWordApplic.Selection.TypeParagraph()
End Sub
'插入指定行數的空行
Public Sub InsertLineBreak(ByVal lines As Integer)
Dim i As Integer
For i = 1 To lines
oWordApplic.Selection.TypeParagraph()
Next
End Sub
'插入表格
Public Sub InsertTable(ByRef table As DataTable)
Dim oTable As Word.Table
Dim rowIndex, colIndex, NumRows, NumColumns As Integer
rowIndex = 1
colIndex = 0

NumRows = table.Rows.Count + 1
NumColumns = table.Columns.Count
oTable = oDocument.Tables.Add(oWordApplic.Selection.Range(), NumRows, NumColumns)


'初始化列
Dim Row As DataRow
Dim Col As DataColumn
For Each Col In table.Columns
colIndex = colIndex + 1
oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName)
Next

'將行添入表格
For Each Row In table.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each Col In table.Columns
colIndex = colIndex + 1
oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row(Col.ColumnName))
Next
Next
oTable.AllowAutoFit = True
oTable.ApplyStyleFirstColumn = True
oTable.ApplyStyleHeadingRows = True
End Sub
'設置對齊
Public Sub SetAlignment(ByVal strType As String)
Select Case strType
Case "center"
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
Case "left"
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
Case "right"
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
Case "justify"
oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify
End Select
End Sub
'設置字體
Public Sub SetStyle(ByVal strFont As String)
Select Case strFont
Case "bold"
oWordApplic.Selection.Font.Bold = 1
Case "italic"
oWordApplic.Selection.Font.Italic = 1
Case "underlined"
oWordApplic.Selection.Font.Subscript = 1
End Select
End Sub
'取消字體風格
Public Sub DissableStyle()
oWordApplic.Selection.Font.Bold = 0
oWordApplic.Selection.Font.Italic = 0
oWordApplic.Selection.Font.Subscript = 0
End Sub
'設置字體字型大小
Public Sub SetFontSize(ByVal nSize As Integer)
oWordApplic.Selection.Font.Size = nSize
End Sub
'跳過本頁
Public Sub InsertPageBreak()
Dim pBreak As Integer
pBreak = CInt(Word.WdBreakType.wdPageBreak)
oWordApplic.Selection.InsertBreak(pBreak)
End Sub
'轉到書簽
Public Sub GotoBookMark(ByVal strBookMark As String)
Dim missing = System.Reflection.Missing.Value
Dim BookMark = CInt(Word.WdGoToItem.wdGoToBookmark)
oWordApplic.Selection.GoTo(BookMark, missing, missing, strBookMark)
End Sub
'判斷書簽是否存在
Public Function BookMarkExist(ByVal strBookMark As String) As Boolean
Dim Exist As Boolean
Exist = oDocument.Bookmarks.Exists(strBookMark)
Return Exist
End Function
'轉到文檔結尾
Public Sub GotoTheEnd()
Dim missing = System.Reflection.Missing.Value
Dim unit = Word.WdUnits.wdStory
oWordApplic.Selection.EndKey(unit, missing)
End Sub
'轉到文檔開頭
Public Sub GotoTheBegining()
Dim missing = System.Reflection.Missing.Value
Dim unit = Word.WdUnits.wdStory
oWordApplic.Selection.HomeKey(unit, missing)
End Sub
'轉到表格
Public Sub GotoTheTable(ByVal ntable As Integer)
'Dim missing = System.Reflection.Missing.Value
'Dim what = Word.WdGoToItem.wdGoToTable
'Dim which = Word.WdGoToDirection.wdGoToFirst
'Dim count = ntable

'oWordApplic.Selection.GoTo(what, which, count, missing)
'oWordApplic.Selection.ClearFormatting()

'oWordApplic.Selection.Text = ""
oRange = oDocument.Tables(ntable).Cell(1, 1).Range
oRange.Select()
End Sub
'轉到表格的某個儲存格
Public Sub GotoTableCell(ByVal ntable As Integer, ByVal nRow As Integer, ByVal nColumn As Integer)
oRange = oDocument.Tables(ntable).Cell(nRow, nColumn).Range
oRange.Select()
End Sub
'表格中轉到右面的儲存格
Public Sub GotoRightCell()
Dim missing = System.Reflection.Missing.Value
Dim direction = Word.WdUnits.wdCell
oWordApplic.Selection.MoveRight(direction, missing, missing)
End Sub
'表格中轉到左面的儲存格
Public Sub GotoLeftCell()
Dim missing = System.Reflection.Missing.Value
Dim direction = Word.WdUnits.wdCell
oWordApplic.Selection.MoveLeft(direction, missing, missing)
End Sub
'表格中轉到下麵的儲存格
Public Sub GotoDownCell()
Dim missing = System.Reflection.Missing.Value
Dim direction = Word.WdUnits.wdCell
oWordApplic.Selection.MoveDown(direction, missing, missing)
End Sub
'表格中轉到上面的儲存格
Public Sub GotoUpCell()
Dim missing = System.Reflection.Missing.Value
Dim direction = Word.WdUnits.wdCell
oWordApplic.Selection.MoveUp(direction, missing, missing)
End Sub
'插入圖片
Public Sub InsertPic(ByVal FileName As String)
Dim missing = System.Reflection.Missing.Value
oWordApplic.Selection.InlineShapes.AddPicture(FileName, False, True, missing)
End Sub

End Class

2008年12月1日 星期一

在word 裡面插入統計圖表

'方法一:用word內建函數
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Imports owc11 = Microsoft.Office.Interop.Owc11

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRng As Word.Range
Dim oShape As Word.InlineShape
Dim oChart As Object
oShape = oDoc.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject( _
ClassType:="MSGraph.Chart", FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False)

oChart = oShape.OLEFormat.Object
oChart.charttype = 5 'xlLine = 4
'都沒有=立體圖(長條圖) 1=一般 4=線圖 5=圓餅圖
oChart.Application.Update()
oChart.Application.Quit()
'If desired, you can proceed from here using the Microsoft Graph
'Object model on the oChart object to make additional changes to the
'chart.

oShape.Width = oWord.InchesToPoints(6.25)
oShape.Height = oWord.InchesToPoints(3.57)
'方法2:用vb.net(word) 內建控制項繪製,轉成圖片,插入word文件
'ACS=AxCharSpace
Dim oWord As New Word.Application
Dim oDoc As Word.Document
Dim oRng As Word.Range
Dim ii As Integer
Dim rowIndex, colIndex As Integer
Dim missing = System.Reflection.Missing.Value
Dim aX, aY
ReDim aX(5)
ReDim aY(5)

Dim DS As New DataSet
DS.Tables.Add()
DS.Tables(0).Columns.Add("姓名")
DS.Tables(0).Columns.Add("成績")

DS.Tables(0).Rows.Add()
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("姓名") = "陳小邦"
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("成績") = "93"

DS.Tables(0).Rows.Add()
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("姓名") = "張小千"
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("成績") = "66"

DS.Tables(0).Rows.Add()
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("姓名") = "林小狗"
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("成績") = "89"

DS.Tables(0).Rows.Add()
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("姓名") = "王宜靜"
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("成績") = "99"

DS.Tables(0).Rows.Add()
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("姓名") = "張大飛"
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("成績") = "78"

DS.Tables(0).Rows.Add()
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("姓名") = "桶一針"
DS.Tables(0).Rows(DS.Tables(0).Rows.Count - 1).Item("成績") = "79"
For ii = 0 To DS.Tables(0).Rows.Count - 1
aX(ii) = DS.Tables(0).Rows(ii).Item("姓名")
aY(ii) = DS.Tables(0).Rows(ii).Item("成績")
Next
oRng = oDoc.Bookmarks.Item("\endofdoc").Range

oRng.InsertParagraphAfter()

Dim Chart1 As Owc11.ChChart
Chart1 = ChartSpace1.Charts.Add() '在ChartSpace1繪圖空間內建一個新圖表(繒圖區)

Dim Chart1_Series1 As Owc11.ChSeries
'宣告資料列...
Chart1_Series1 = Chart1.SeriesCollection.Add(0) '在Chart1圖表中加一個資料列
Chart1_Series1.Type = Owc11.ChartChartTypeEnum.chChartTypeBarClustered

'命名資料系列(名稱將在圖例中顯示出來)
Chart1_Series1.SetData(Owc11.ChartDimensionsEnum.chDimSeriesNames, Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, "成績")


'將資料組中的資料填入圖表


Chart1_Series1.SetData(Owc11.ChartDimensionsEnum.chDimCategories, Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, aX) '姓名軸
Chart1_Series1.SetData(Owc11.ChartDimensionsEnum.chDimValues, Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, aY) '成績軸
Chart1_Series1.SetData(ChartDimensionsEnum.chDimHighValues, Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, 100)
'匯出圖片
ACS.ExportPicture(Application.StartupPath & "\1.GIF", "GIF", ACS.Width, ACS.Height)
'尋找文件結尾
missing = System.Reflection.Missing.Value
Dim unit = Word.WdUnits.wdStory
oWord.Selection.EndKey(unit, missing)

oWord.Selection.InlineShapes.AddPicture(Application.StartupPath & "\1.GIF", False, True, missing)
'Add text after the chart.


oRng.InsertParagraphAfter()
oDoc.SaveAs(Application.StartupPath & "\1.doc")
oDoc.Close(True)
oWord.Quit(True)
oDoc = Nothing
oWord = Nothing