創(chuàng)新互聯(lián)建站咨詢電話:028-86922220,為您提供成都網(wǎng)站建設(shè)網(wǎng)頁設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),創(chuàng)新互聯(lián)建站網(wǎng)頁制作領(lǐng)域10年,包括廣告推廣等多個(gè)方面擁有多年的營(yíng)銷推廣經(jīng)驗(yàn),選擇創(chuàng)新互聯(lián)建站,為企業(yè)保駕護(hù)航!
選中要修改的所有行,在行標(biāo)
(1 2 3……)處單擊右鍵->行高,然后輸入相應(yīng)值就可以了
右擊左側(cè)序號(hào)欄,選擇設(shè)置行高。。。
HSSFWorkbook wb = new HSSFWorkbook();HSSFSheet sheet = wb.createSheet();HSSFRow row = sheet.createRow(0);然后使用row.setHeight()或者row.setHeightInPoints()來調(diào)整行高
office 2007中是這樣的:選中要設(shè)置的行,在開始-->單元格-->格式-->行高中設(shè)置。
選擇要設(shè)置行高的一行或多行點(diǎn)擊右鍵,選擇“行高”,輸入行高數(shù)字,點(diǎn)擊確定,就設(shè)置好了行高。
excel中行高的設(shè)置方法如下:一、打開excel,把鼠標(biāo)指針放到1、2、3等序號(hào)之間的中間線上,此時(shí)鼠標(biāo)會(huì)變成一個(gè)“十”字狀,可以上下拖動(dòng)的狀態(tài)。
二、此時(shí)可以拖著這條中間線向下拖動(dòng) ,根據(jù)需要,想讓行高變多少就拖多少。
三、當(dāng)拖動(dòng)到需要的指定位置,松開鼠標(biāo),此時(shí)一整行的單元格高度就都被設(shè)置成了一樣的行高。如果想把一整列單元格全部設(shè)置為一樣的高度,就用鼠標(biāo)左鍵選定左邊的數(shù)字欄,向下拖動(dòng)即可。拖動(dòng)完成,這一列全部選定,用鼠標(biāo)指針向下拖動(dòng)某二個(gè)單元格之間的中間線,拖動(dòng)到理想位置的大小,松開鼠標(biāo)。
選中你要設(shè)置行高的單元格,點(diǎn)菜單欄的格式—行—行高。
選取行,再在行號(hào)的間隙中調(diào)整就可以調(diào)整行高了。列也如此。另外也可以這樣: 選取行,右擊,行高。列的話也類似的。
在excel里面,把鼠標(biāo)放在最左邊的數(shù)字上變成箭頭符號(hào),點(diǎn)擊鼠標(biāo)左鍵覆蓋要設(shè)置的范圍,在點(diǎn)擊右鍵選擇“行高”設(shè)置就可以了
EXCEL的行高度和列寬度單位是不一樣的。
1,EXCEL列高度的單位是磅,Apache POI的行高度單位是緹(twip):1英寸=72磅=25.4毫米=1440緹1磅=0.353毫米=20緹POI中的行高=Excel的行高度*20Excel的行高度=POI中的行高/20這里順便把像素的換行方法說一下:DPI = 1英寸內(nèi)可顯示的像素點(diǎn)個(gè)數(shù)。通常電腦屏幕是96DPI, IPhone4s的屏幕是326DPI, 普通激光黑白打印機(jī)是400DPI要計(jì)算POI行高或者Excel的行高,就先把它行轉(zhuǎn)換到英寸,再乘小DPI就可以得到像素像素 = (磅/72)*DPI像素= (Excel的行高度/72)*DPI像素= (POI中的行高/20/72)*DPIExcel的行高度=像素/DPI*72POI中的行高=像素/DPI*72*20例如在電腦屏幕上, Excel默認(rèn)行高度為13.5, (13.5/72)*96=18像素,而Excel中也確實(shí)顯示的就是18像素。
2,EXCEL列寬度的單位是字符個(gè)數(shù)
(2014-08-18備注:關(guān)于Excel的寬度計(jì)算的詳細(xì)介紹在這篇文章Excel的寬度怎么算的?)在excel2003以上的版本中,可以建立一個(gè)空白的xls文檔并將第一列寬度拉到10。然后在A1單元格中輸入1234567890可以看到單元格正好可以容納這十個(gè)字符。
一個(gè)字符的寬度是通過測(cè)量1234567890這十個(gè)字符在默認(rèn)字體(通常是宋體11號(hào)字,視版本可能不同)下的平均寬度得到的。只要記住一個(gè)字符的寬度是8像素 (2013-10-29備注:一個(gè)字符的寬度取決于Excel文件中的第一個(gè)字體大小,并不一定就是8像素)就可以了。
一個(gè)單元格實(shí)際的像素寬度還要在(字符個(gè)數(shù) * 默認(rèn)字符的寬度)的基礎(chǔ)上前后各加2個(gè)像素的空白邊。另外字符之間會(huì)疊加一個(gè)像素,在計(jì)算時(shí)也要減去:(2013-10-29備注:一個(gè)字符的邊距不一定只是2像素,和字體有關(guān)系)像素 = 2個(gè)像素空白 + (字符個(gè)數(shù) * 默認(rèn)字符的寬度) + 2個(gè)像素空白 - (字符個(gè)數(shù) - 1)整理一下,公式變成:像素 = 5 + (字符個(gè)數(shù) * (默認(rèn)字符的寬度 - 1))代入默認(rèn)字符寬度8:像素 = 5 + (字符個(gè)數(shù) * 7)POI中的字符寬度算法是:double 寬度 = (字符個(gè)數(shù) * (字符寬度 - 1) + 5) / (字符寬度 - 1) * 256;然后再四舍五入成整數(shù)。最后把我寫的一個(gè)工具類貼上來,方便使用。public class HSSFUtil private static final short TWIPS_PER_PIEXL = 15; //1 Pixel = 1440 TPI / 96 DPI = 15 Twips public static short pixel2PoiHeight(int pixel) return (short) (pixel * TWIPS_PER_PIEXL); } public static int poiHeight2Pixel(short height) return height / TWIPS_PER_PIEXL; } //像素轉(zhuǎn)poi寬度 public static int pixel2PoiWidth(FontInfo fontInfo, int pixel) double numChars = pixel2Character(fontInfo, pixel); numChars *= fontInfo.charWidth; numChars += fontInfo.spacing; numChars /= fontInfo.charWidth; numChars *= 256; return (int)numChars; } //poi寬度轉(zhuǎn)像素 public static int poiWidth2Pixel(FontInfo fontInfo, int poiWidth) double numChars = poiWidth2Character(fontInfo, poiWidth); return character2Piexl(fontInfo, numChars); } public static double poiWidth2Character(FontInfo fontInfo, int poiWidth) double numChars = poiWidth / 256.0 - (fontInfo.spacing * 1.0 / fontInfo.charWidth); //2位小數(shù) return new BigDecimal(numChars).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); } public static int character2PoiWidth(FontInfo fontInfo, double numChars) double w = (numChars + (fontInfo.spacing * 1.0 / fontInfo.charWidth)) * 256; return (int) w; } //excel字符轉(zhuǎn)像素 public static int character2Piexl(FontInfo fontInfo, double numChars) double pixel = fontInfo.charWidth * numChars + fontInfo.spacing; return (int)pixel; } //excel像素轉(zhuǎn)字符 public static double pixel2Character(FontInfo fontInfo, int pixel) double numChars = (pixel - fontInfo.spacing) * 1.0 / fontInfo.charWidth; return new BigDecimal(numChars).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); } //獲得工作簿默認(rèn)字符寬度 public static FontInfo getDefaultCharWidth(Workbook book) //博客沒人氣,我已刪除此段代碼,請(qǐng)自行研究或者留郵箱 } //獲得不同字體的字符邊距 private static int getSpacing(int fontHeightInPoints, int charWidth) //博客沒人氣,我已刪除此段代碼,請(qǐng)自行研究或者留郵箱 } }
你好,去看一下官方的api文檔,或許你就會(huì)了https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/sheet.html
在開發(fā)中經(jīng)常需要用到對(duì)Excel文件的操作,POI生成excel實(shí)現(xiàn)自動(dòng)調(diào)整行高的代碼如下: import javaioFileOutputStream; import orgapachepoihssfusermodelHSSFCell; import orgapachepoihssfusermodelHSSFCellStyle; import orgapac
在開發(fā)中經(jīng)常需要用到對(duì)excel文件的操作,poi生成excel實(shí)現(xiàn)自動(dòng)調(diào)整行高的代碼如下:import java.io.fileoutputstream;import org.apache.poi.hssf.usermodel.hssfcell;import org.apache.poi.hssf.usermodel.hssfcellstyle;import org.apache.poi.hssf.usermodel.hssffont;import org.apache.poi.hssf.usermodel.hssfrow;import org.apache.poi.hssf.usermodel.hssfsheet;import org.apache.poi.hssf.usermodel.hssfworkbook;import org.apache.poi.hssf.usermodel.hssfrichtextstring;import org.apache.poi.hssf.usermodel.hssfdataformat;import org.apache.poi.hssf.usermodel.hssfcomment;import org.apache.poi.hssf.usermodel.hssfpatriarch;import org.apache.poi.hssf.usermodel.hssfclientanchor;public class poicreateexceltest public static void main(string[] args) /** * @see for more */ // 創(chuàng)建新的excel 工作簿 hssfworkbook workbook = new hssfworkbook(); // 在excel工作簿中建一工作表,其名為缺省值, 也可以指定sheet名稱 hssfsheet sheet = workbook.createsheet(); //hssfsheet sheet = workbook.createsheet("sheetname"); // 用于格式化單元格的數(shù)據(jù) hssfdataformat format = workbook.createdataformat(); // 創(chuàng)建新行(row),并將單元格(cell)放入其中. 行號(hào)從0開始計(jì)算. hssfrow row = sheet.createrow((short) 1); // 設(shè)置字體 hssffont font = workbook.createfont(); font.setfontheightinpoints((short) 20); //字體高度 font.setcolor(hssffont.color_red); //字體顏色 font.setfontname("黑體"); //字體 font.setboldweight(hssffont.boldweight_bold); //寬度 font.setitalic(true); //是否使用斜體// font.setstrikeout(true); //是否使用劃線 // 設(shè)置單元格類型 hssfcellstyle cellstyle = workbook.createcellstyle(); cellstyle.setfont(font); cellstyle.setalignment(hssfcellstyle.align_center); //水平布局:居中 cellstyle.setwraptext(true); // 添加單元格注釋 // 創(chuàng)建hssfpatriarch對(duì)象,hssfpatriarch是所有注釋的容器. hssfpatriarch patr = sheet.createdrawingpatriarch(); // 定義注釋的大小和位置,詳見文檔 hssfcomment comment = patr.createcomment(new hssfclientanchor(0, 0, 0, 0, (short)4, 2, (short) 6, 5)); // 設(shè)置注釋內(nèi)容 comment.setstring(new hssfrichtextstring("可以在poi中添加注釋!")); // 設(shè)置注釋作者. 當(dāng)鼠標(biāo)移動(dòng)到單元格上是可以在狀態(tài)欄中看到該內(nèi)容. comment.setauthor("xuys."); // 創(chuàng)建單元格 hssfcell cell = row.createcell((short) 1); hssfrichtextstring hssfstring = new hssfrichtextstring("hello world!"); cell.setcellvalue(hssfstring);//設(shè)置單元格內(nèi)容 cell.setcellstyle(cellstyle);//設(shè)置單元格樣式 cell.setcelltype(hssfcell.cell_type_string);//指定單元格格式:數(shù)值、公式或字符串 cell.setcellcomment(comment);//添加注釋 //格式化數(shù)據(jù) row = sheet.createrow((short) 2); cell = row.createcell((short) 2); cell.setcellvalue(11111.25); cellstyle = workbook.createcellstyle(); cellstyle.setdataformat(format.getformat("0.0")); cell.setcellstyle(cellstyle); row = sheet.createrow((short) 3); cell = row.createcell((short) 3); cell.setcellvalue(9736279.073); cellstyle = workbook.createcellstyle(); cellstyle.setdataformat(format.getformat("#,##0.0000")); cell.setcellstyle(cellstyle); sheet.autosizecolumn((short)0); //調(diào)整第一列寬度 sheet.autosizecolumn((short)1); //調(diào)整第二列寬度 sheet.autosizecolumn((short)2); //調(diào)整第三列寬度 sheet.autosizecolumn((short)3); //調(diào)整第四列寬度 try fileoutputstream fileout = new fileoutputstream("c:/3.xls"); workbook.write(fileout); fileout.close(); } catch (exception e) system.out.println(e.tostring()); } }}
標(biāo)題名稱:poi設(shè)置行高,excel怎么設(shè)置行高
分享路徑:http://chinadenli.net/article48/iceehp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站排名、外貿(mào)建站、移動(dòng)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)