pio中關於excel單元問題

2021-08-11 12:27:32 字數 2905 閱讀 7555

pio中設定單元格式問題:

1、加刪除線

//新建刪除線單元格格式

hssfcellstyle cellstyle2 = wb.createcellstyle();  

cellstyle2.setalignment(hssfcellstyle.align_left); // 指定單元格居中對齊  

cellstyle2.setwraptext(true);// 指定單元格自動換行 

hssfdataformat format2= wb.createdataformat();

cellstyle2.setdataformat(format2.getformat("#,##0.000"));

cellstyle2.setborderbottom(hssfcellstyle.border_thin); //下邊框

cellstyle2.setborderleft(hssfcellstyle.border_thin);//左邊框

cellstyle2.setbordertop(hssfcellstyle.border_thin);//上邊框

cellstyle2.setborderright(hssfcellstyle.border_thin);//右邊框

//設定刪除線字型

hssffont font2 = wb.createfont();

font2.setfontname("arial");  

font2.setstrikeout(true);//設定刪除線

cellstyle2.setfont(font2);

//        style.setfillforegroundcolor(indexedcolors.grey_25_percent.getindex());  

2、加背景色

//新建背景色置灰單元格格式

hssfcellstyle cellstyle3 = wb.createcellstyle();  

cellstyle3.setalignment(hssfcellstyle.align_left); // 指定單元格居中對齊  

cellstyle3.setwraptext(true);// 指定單元格自動換行 

hssfdataformat format3= wb.createdataformat();

cellstyle3.setdataformat(format3.getformat("#,##0.000"));

cellstyle3.setborderbottom(hssfcellstyle.border_thin); //下邊框

cellstyle3.setborderleft(hssfcellstyle.border_thin);//左邊框

cellstyle3.setbordertop(hssfcellstyle.border_thin);//上邊框

cellstyle3.setborderright(hssfcellstyle.border_thin);//右邊框

cellstyle3.setfillforegroundcolor(indexedcolors.grey_25_percent.getindex());

cellstyle3.setfillpattern(cellstyle.solid_foreground);

3、金額格式設定

//設定單元格樣式 

hssfcellstyle cellstyle = wb.createcellstyle();  

cellstyle.setalignment(hssfcellstyle.align_left); // 指定單元格居中對齊  

cellstyle.setwraptext(true);// 指定單元格自動換行 

hssfdataformat format= wb.createdataformat();

cellstyle.setdataformat(format.getformat("#,##0.000"));

cellstyle.setborderbottom(hssfcellstyle.border_thin); //下邊框

cellstyle.setborderleft(hssfcellstyle.border_thin);//左邊框

cellstyle.setbordertop(hssfcellstyle.border_thin);//上邊框

cellstyle.setborderright(hssfcellstyle.border_thin);//右邊框

// 單元格字型  

hssffont font = wb.createfont();  

font.setfontname("arial");  

cellstyle.setfont(font);

//匯出金額是設定單元格樣式

hssfcellstyle mondycellstyle = wb.createcellstyle();  

mondycellstyle.setalignment(hssfcellstyle.align_center); // 指定單元格居中對齊  

mondycellstyle.setwraptext(true);// 指定單元格自動換行 

mondycellstyle.setborderbottom(hssfcellstyle.border_thin); //下邊框

mondycellstyle.setborderleft(hssfcellstyle.border_thin);//左邊框

mondycellstyle.setbordertop(hssfcellstyle.border_thin);//上邊框

mondycellstyle.setborderright(hssfcellstyle.border_thin);//右邊框

4、合併單元格

5、確保合併單元格都有對應邊框

總結:workbook、sheet、row、cell

excel中單元格帶引號問題

現象 excel中某個單元格拷出結果 單元格 select from dual where 1 1 拷出到文字結果 select from dual where 1 1 原因 excel中乙個單元格的內容帶著換行符,複製出來的時候預設在前後加了引號.去掉引號思路 因為存在換行,所以excel帶了引號...

openpyxl讀取Excel中單個單元格的資料

將測試資料使用excel來處理 python中處理excel的模組非常多,比如xlrd,xlwd 讀寫分開,不太方便 使用openpyxl同時支援讀寫操作,需要安裝後才能使用 pip install openpyxl 如果報錯,需要更新pip,python m pip install upgrade...

excel中快速選定單元單元格區域

如果工作表中有單元格使用了條件公式 而且它們之間並不連續,那麼要想一次把它們全部選中,最好的辦法就是使用定位條件。在excel2007中,我們應該單擊功能區的開始選項卡,編輯 功能組中的查詢和選擇命令按鈕右下角的小三角形,在彈出選單 中選擇定位條件命令,開啟定位條件對話方塊,選中條件格式單遠項,確定...