There's nothing to write about today. " . NET writes a picture file to EXCEL using the Npoi component "
First look at the effect:
I added the head, this should not be difficult!
Look at the code again:
private void Button1_Click (object sender, EventArgs e) {///Picture file full path E:\11\DKSG9869_1.jpg St Ring Path = TxtPath.Text.Trim (); int rowIndex = 0;//first line int colindex = 1;//second column//create workbook Hssfworkbook Hssfworkbook hssfworkb Ook = new Hssfworkbook (); Create a worksheet ssss hssfsheet sheet = hssfworkbook on the basis of the workbook Hssfworkbook. Createsheet ("Ssss"); On the basis of worksheet ssss, create a row row hssfrow row = sheet. CreateRow (RowIndex); Sets the height of rows row. Height = 1020; Create cell 0 (also called the first column) Hssfcell cell0 = row on the basis of rows row. Createcell (0); Sets the default width of the first column of the cell cell0. Sheet.defaultcolumnwidth = 1000; Sets the default height cell0 for the first column of the cell. Sheet.defaultrowheight = 1000; Writes the value cell0 to the cell (the first column). Setcellvalue ("Npoi"); Create cell 1 (also known as the second column) on the basis of rows row Hssfcell cell1 = row. Createcell (Colindex); Set the default width for the second column of a cell Cell1. Sheet.defaultcolumnwidth = 1000; Sets the default height cell1 for the second column of the cell. Sheet.defaultrowheight = 1000; Cell1. Sheet.createdrawingpatriarch (). Createpicture (New Hssfclientanchor (0, 0, 1010, 252, Colindex, RowIndex, Colindex, RowIndex), Hssfworkbook. AddPicture (System.IO.File.ReadAllBytes (path), hssfworkbook.picture_type_jpeg)). LineStyle = Hssfpicture.linestyle_none; FileStream file = new FileStream (@ "1.xls", FileMode.Create); Hssfworkbook. Write (file); File. Close (); }
Needless to say, in this sentence.
Cell1. Sheet.createdrawingpatriarch (). Createpicture (New Hssfclientanchor (0, 0, 1010, 252, Colindex, RowIndex, Colindex, RowIndex), Hssfworkbook. AddPicture (System.IO.File.ReadAllBytes (path), hssfworkbook.picture_type_jpeg)). LineStyle = Hssfpicture.linestyle_none;
. NET EXCEL Npoi Pictures