ExcelPlate


【功能說明】

用途:使用於 Client 端,讓 User 可以根據資料庫數據按照一定規格輸出到 Excel

【元件屬性】

Name( 名稱 )(string)

元件名稱,用於識別該元件。

DataSource ( 資料源 )(Collection)

用於 將一些資料源和一個資料源標記關聯,這樣文檔就能取得資料源中的資料。

    Caption(string) : 題,由 User 自行輸入。

     DataMember(string): 資料内容,在 User 選定 DataSource 后自 在下拉選項中添加進入。

     DataSource(string): 資料源,添加希望關聯的 InfoBindingSource

    ImageColumns (collection) : 圖片欄位,在資料表中如果存在欄位為 Image 時,須設定次屬性,屬性内容如下 :

        ColumnName (string): 位名稱, 用於設定圖片類型的 位。

        DefaultPath (string): 默認路 ,當希望顯示圖片的 string 類型, 僅存放檔的目錄資訊,那麼可以通過設定 DefaultPath ,在套表時, DefaultPath + Photo 位元 的值去伺服器下載圖片

Excel Tag (Excel )(Collection)

用於 一些運算式和 個自定義 記關聯,這 文檔就能取得運算式的值。

    DataField (string): 記名稱,有 User 自行輸入。

    Exp(string): 運算式

    Format(string): 用於 規定輸出運算式的格式。

ExcelFile ( 範本文件名 )(string)

表示輸入範本文檔的檔案名(包括尾碼名 xls ),範本文檔要存放在 EEPNetClient 所在 Folder 中的當前解決方案的 Folder WebClient 所在 Folder 裏,在運行時用戶端會自動更新這個範本。

OutputPath ( 輸出路徑 )(string)

表示存放輸出文檔的目錄,如果目錄不存在的話會在運行時自動產生。

OutputFileName ( 輸出文件的名稱 )(string)

此屬性鍵入值為輸出文檔的檔案名 ( 包括尾碼名 xls ) ,如果不設置的話,會輸出一個以輸出時間為檔案名的文檔。

PlateMode ( 套表文檔的格式 )( enum)

此屬性有兩個選擇,一個為 Xml ,另一個為 Com ,選擇 Xml ,這個模式的速度比較快,消耗的資源比較少,最終輸出的文檔也是以 xml 格式保存的。如果選擇 Com ,這個模式的資源有一定的消耗,最終的輸出格式為 Excel 文檔的格式,但支援所有的文檔內容,尤其文檔中存有自定義的圖片或者統計圖時,由於不能保存為 xml 格式,因此只有選擇 Com 了。

OutputMode ( 套表結束後的輸出模式 )( enum)

次屬性共有沒有動作( None , 打開輸出文檔( Launch , 將輸出文檔以附件發給收件人 Email )三种選擇。

ShowAction ( 顯示套表過程 )( bool)

當設定為 True 時,在運行套表過程時,會顯示一個進度條及一些文字,指示當前套表的情況,如果設定為 False ,則不會出現這個進度條。

MarkException ( 標記錯誤資訊 )( bool)

設定為 True 時,如果套表過程中發生 異常 ,則會將異常資訊寫入到輸出文檔對應的標記中,設定為 False ,則不會改變這個產生異常的標記。

EmailAddress (Email 地址 )(string )

當選擇 OutputMode Email 時,將使用該屬性把文件作爲附件發送到設定的 Email 地址中。

EmailTitle ( 郵件主題 )(string)

當選擇 OutputMode Email 時,會將 Email 主題設定為該屬性設置。

 

事件

AfterOutput(EventArgs e)

WordPlate 還提供了一個輸出后的事件,可在輸出結束後發生,可以在這個事件中加入用戶自定義的程式。

private void Excel Plate 1 _AfterOutput( objectsender, EventArgse)

   {

        MessageBox.Show( "Finish");

   }

 

【功能函數】

Output( int Mode)

運用此方法可以將 Excel 文件進行輸出, OutPut 方法有一個整型參數,當參數為 1 時,輸出前會再次讓用戶選擇輸出結束後的工作,可以選擇沒有動作( None , 打開輸出文檔( Launch , 將輸出文檔以附件發給收件人( Email );不為 1( 其他任何數建議使用 0) 時,就按照 OutputMode 的設定進行輸出後的工作。

 

其它説明

ExcelPlate

 

範例

使用 ExcelPlate 不要透過 Excel 即可直接印表 可在 ExcelPlate AfterOutput 事件中加入 印表 程式,如下:

using System.Reflection;

using System.Runtime.InteropServices;

private voidexcelPlate1_AfterOutput( objectsender, EventArgse)

{

  Excel. ApplicationobjExcel = newExcel. Application();

  objExcel.Visible= false;

  Excel. WorkbookobjWorkBook = objExcel.Workbooks.Open(excelPlate1.FilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

   try

  {

     objWorkBook.PrintOut(1, 1, 1, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

  }

   finally

 {

     objExcel.Quit();

      Marshal.ReleaseComObject(objExcel);

      Marshal.ReleaseComObject(objWorkBook);

     objExcel = null;

     objWorkBook = null;

      GC.Collect();

  }

}

PrintOut 為打印的函數 , 第一個參數是打印起始頁 , 第二個參數打印結束頁 , 第三個參數是打印的份數

 

使用 ExcelPlate 每一次列印至 Excel , 防止 出現 output.xls has already exsited.Wouldyou like to overwrite it ”, 可在 ExcelPlate.Output () 前刪除 原有 檔案,如下:

using System.IO;

string filepath = string.Empty;

if (excelPlate1.OutputPath.EndsWith( "\\"))

{

  filepath = excelPlate1.OutputPath + excelPlate1.OutputFileName;

}

else

{

  filepath = excelPlate1.OutputPath + "\\"+ excelPlate1.OutputFileName;

}

if (File.Exists(filepath))

{

   try

  {

     File.Delete(filepath);

  }

   catch

  {

  }

}

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)