原創(chuàng)|其它|編輯:郝浩|2012-10-16 10:46:10.000|閱讀 4177 次
概述:詳述了Aspose.Cells相應(yīng)的基本操作。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
詳述了Aspose.Cells相應(yīng)的基本操作。
Workbook Workbook workBook = new Workbook();
屬性:
名稱 | 值類型 | 說明 |
Colors | Color[] | 獲取或設(shè)置Excel顏色 |
ConvertNumericData | bool |
獲取或設(shè)置是否將字符串轉(zhuǎn)換至數(shù)字?jǐn)?shù)據(jù) 默認(rèn)值為 true |
DataSorter | DataSorter | 獲取或設(shè)置數(shù)據(jù)分級 |
Date1904 | bool | |
DefaultStyle | Aspose.Cells.Style | 獲取或設(shè)置工作簿默認(rèn)樣式 |
HasMacro | bool | 獲取工作簿是否包含宏觀調(diào)控或宏 |
IsHScrollBarVisible | bool |
獲取或設(shè)置左部滾動條(控制行) 默認(rèn)值為true |
IsProtected | bool | 獲取工作簿保護狀態(tài) |
IsVScrollBarVisible | bool |
獲取或設(shè)置底部滾動條(控制列) 默認(rèn)值為true |
Language | CountryCode --枚舉類型 |
獲取或設(shè)置語言 默認(rèn)為當(dāng)前計算機區(qū)域 |
Password | string | 獲取或設(shè)置工作簿密碼 |
ReCalcOnOpen | bool | 獲取或設(shè)置是否重新計算所有打開文件的公式 |
Region | CountryCode --枚舉類型 |
獲取或設(shè)置工作簿區(qū)域(指當(dāng)前使用者區(qū)域) 默認(rèn)為當(dāng)前計算機區(qū)域 |
Shared | bool |
獲取或設(shè)置當(dāng)前工作簿是否共享 默認(rèn)為false |
ShowTabs | bool |
獲取或設(shè)置是否顯示標(biāo)簽(工作表標(biāo)簽) 默認(rèn)為true |
Styles | Styles | 樣式集合 |
Worksheets | Worksheet |
事件:
CalculateFormula(bool ignoreError ,ICustomFunction customFunction) +3 |
void | 計算公式 |
ChangePalette(Color color,int index) | void | 設(shè)置當(dāng)前顏色在調(diào)色版中顯示順序 |
Combine(Workbook secondWorkbook) | void | 聯(lián)合工作簿,將secondWorkbook 工作簿中workSheet追加到當(dāng)前工作簿中 |
Copy(Workbook source) | void | 拷貝工作簿到當(dāng)前工作簿 |
Decrypt(string password) | void | 解除工作簿密碼 |
IsColorInPalette(Color color) | bool | 將color加入到當(dāng)前Excel調(diào)色版 |
LoadData(string fileName) LoadData(System.IO.Stream stream) | void | 加載Excel到當(dāng)前Workbook中 |
Open(string fileName, FileFormatType.Default, string password ); +8 |
void | 打開Excel文件 |
Protect(ProtectionType.All, string password); |
void | 寫保護,并設(shè)置取消工作簿保護密碼 |
RemoveExternalLinks() | void | 移除外部鏈接 |
RemoveMacro() | void | 移除宏 |
Replace (string PlaceHolder, string newValue); +8 |
void | 工作簿中類型和值完全符合的單元格,將其替換為新值或?qū)ο?nbsp; |
Save(Server.UrlEncode("測試.xls"), FileFormatType.Default, SaveType.OpenInExcel, Response);+8 |
Void | 保存工作簿 |
SaveToStream() |
System. |
將工作簿寫入內(nèi)存流中 |
Unprotect(string password); | Void | 取消工作簿保護狀態(tài) |
ValidateFormula(string formula) | bool | 驗證公式 |
-----------
using System; using System.Collections.Generic; using System.Text; using Aspose.Cells; using System.Data; namespace CRM.Common { public class AsposeExcel { private string outFileName = ""; private Workbook book = null; private Worksheet sheet = null; private log4net.ILog log = log4net.LogManager.GetLogger(typeof(AsposeExcel)); public AsposeExcel(string outfilename,string tempfilename) { outFileName = outfilename; book = new Workbook(); book.Open(tempfilename); sheet = book.Worksheets[0]; } private void AddTitle(string title, int columnCount) { sheet.Cells.Merge(0, 0, 1, columnCount); sheet.Cells.Merge(1, 0, 1, columnCount); Cell cell1 = sheet.Cells[0, 0]; cell1.PutValue(title); cell1.Style.HorizontalAlignment = TextAlignmentType.Center; cell1.Style.Font.Name = "黑體"; cell1.Style.Font.Size = 14; cell1.Style.Font.IsBold = true; Cell cell2 = sheet.Cells[1, 0]; cell1.PutValue("查詢時間:" + DateTime.Now.ToLocalTime()); cell2.SetStyle(cell1.Style); } private void AddHeader(DataTable dt) { Cell cell = null; for (int col = 0; col < dt.Columns.Count; col++) { cell = sheet.Cells[0, col]; cell.PutValue(dt.Columns[col].ColumnName); cell.Style.Font.IsBold = true; } } private void AddBody(DataTable dt) { for (int r = 0; r < dt.Rows.Count; r++) { for (int c = 0; c < dt.Columns.Count; c++) { sheet.Cells[r + 3, c].PutValue(dt.Rows[r][c].ToString()); } } } public void DatatableToExcel(DataTable dt) { try { //sheet.Name = sheetName; //AddTitle(title, dt.Columns.Count); //AddHeader(dt); AddBody(dt); sheet.AutoFitColumns(); //sheet.AutoFitRows(); book.Save(outFileName); } catch (Exception e) { log.Error("導(dǎo)出Excel失敗!" + e.Message); throw e; } } } }
導(dǎo)入就不說了。導(dǎo)入為datetable之后就自己操作就OK。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:lhuser的專欄-博客園