日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

使用Aspose.Cells的基础知识整理

發(fā)布時(shí)間:2025/6/17 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Aspose.Cells的基础知识整理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用Aspose.Cells的基礎(chǔ)知識(shí)整理

轉(zhuǎn)自 http://www.cnblogs.com/kenblove/archive/2009/01/07/1371104.html

這兩天用Aspose.Cells構(gòu)建一個(gè)Excel報(bào)表,感覺(jué)這個(gè)組件還比較好用.記錄一下常用的使用知識(shí):

1.創(chuàng)建Workbook和Worksheet

?


Workbook?wb?=?new?Workbook();
wb.Worksheets.Clear();
wb.Worksheets.Add(
"New?Worksheet1");//New Worksheet1是Worksheet的name
Worksheet?ws?
=?wb.Worksheets[0];

?

如果直接用下邊兩句則直接使用默認(rèn)的第一個(gè)Worksheet:

?


Workbook?wb?=?new?Workbook();
Worksheet?ws?
=?wb.Worksheets[0];

?

2.給Cell賦值設(shè)置背景顏色并加背景色:

?


Cell?cell?=?ws.Cells[0,?0];
cell.PutValue(
"填充"); //必須用PutValue方法賦值
cell.Style.ForegroundColor?
=?Color.Yellow;
cell.Style.Pattern?
=?BackgroundType.Solid;
cell.Style.Font.Size?
=?10;
cell.Style.Font.Color?
=?Color.Blue;

?

自定義格式:

?


cell.Style.Custom?=?"ddd,?dd?mmmm?'yy";

?

旋轉(zhuǎn)字體:

?


cell.Style.Rotation?=?90;

?

?

3.設(shè)置Range并賦值加Style

?

range1
int?styleIndex?=?wb.Styles.Add();
Style?style?
=?wb.Styles[styleIndex];
style.ForegroundColor?
=?Color.Yellow;
style.Pattern?
=?BackgroundType.Solid;
style.Font.Size?
=?10;

//從Cells[0,0]開(kāi)始創(chuàng)建一個(gè)2行3列的Range
Range?range?=?ws.Cells.CreateRange(0,?0,?2,?3);
Cell?cell?
=?range[0,?0];
cell.Style.Font?
=?9;
range.Style?
=?style;
range.Merge();

?

注意Range不能直接設(shè)置Style.必須先定義style再將style賦給Style.其他設(shè)置和Cell基本一致.Range的Style會(huì)覆蓋Cell定義的Style.另外必須先賦值再傳Style.否則可能不生效.

?

4.使用Formula:

?

formula1
ws.Cells[0,0].PutValue(1);
ws.Cells[
1,0].PutValue(20);
ws.Cells[
2,0].Formula="SUM(A1:B1)";
wb.CalculateFormula(
true);

?

Save Excel文件的時(shí)候必須調(diào)用CalculateFormula方法計(jì)算結(jié)果.

?

5.插入圖片:

?

pictures1
string?imageUrl?=?System.Web.HttpContext.Current.Server.MapPath("~/images/log_topleft.gif");
ws.Pictures.Add(
10,?10,?imageUrl);

?

6.使用Validations:

?

validations1
Cells?cells?=?ws.Cells;

cells[
12,?0].PutValue("Please?enter?a?number?other?than?0?to?10?in?B1?to?activate?data?validation:");
cells[
12,?0].Style.IsTextWrapped?=?true;

cells[
12,?1].PutValue(5);
Validations?validations?
=?totalSheet.Validations;

Validation?validation?
=?validations[validations.Add()];
//Set?the?data?validation?type
validation.Type?=?ValidationType.WholeNumber;
//Set?the?operator?for?the?data?validation
validation.Operator?=?OperatorType.Between;
//Set?the?value?or?expression?associated?with?the?data?validation
validation.Formula1?=?"0";
//the?value?or?expression?associated?with?the?second?part?of?the?data?validation
validation.Formula2?=?"10";

validation.ShowError?
=?true;
//Set?the?validation?alert?style
validation.AlertStyle?=?ValidationAlertType.Information;
//Set?the?title?of?the?data-validation?error?dialog?box
validation.ErrorTitle?=?"Error";
//Set?the?data?validation?error?message
validation.ErrorMessage?=?"?Enter?value?between?0?to?10";
//Set?the?data?validation?input?message
validation.InputMessage?=?"Data?Validation?using?Condition?for?Numbers";
validation.IgnoreBlank?
=?true;
validation.ShowInput?
=?true;
validation.ShowError?
=?true;

//設(shè)置Validations的區(qū)域,因?yàn)楝F(xiàn)在要Validations的位置是12,1,所以下面設(shè)置對(duì)應(yīng)的也要是12,1
CellArea?cellArea;
cellArea.StartRow?
=?12;
cellArea.EndRow?
=?12;
cellArea.StartColumn?
=?1;
cellArea.EndColumn?
=?1;
validation.AreaList.Add(cellArea);

/*
要注意?的地方Validations?也是和Range的Style一樣,要新增的,否則不生效
*/

?

上邊不過(guò)是基礎(chǔ)中的基礎(chǔ),要了解更多就要自己不斷的嘗試了.下邊奉上幫助文檔和DLL:

點(diǎn)擊這里下載!

?

附送Excel支持的56種顏色: Excel報(bào)表支持的56種顏色(Excel2003及以下版本)

? posted on 2009-11-18 14:42 NET未來(lái)之路 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/lonelyxmas/archive/2009/11/18/1605366.html

總結(jié)

以上是生活随笔為你收集整理的使用Aspose.Cells的基础知识整理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。