ExcelHelper类
/// <summary>
/// ExcelHelper类
/// </summary>
using System;
using System.IO;
using System.Data;
using System.Collections;
using System.Data.OleDb;
using System.Web; using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using System.Reflection; class ExcelHelper
{
string myFileName;
Application myExcel;
Workbook myWorkBook; /// <summary>
/// 构造函数,不创建Excel工作薄
/// </summary>
public ExcelHelper()
{
} /// <summary>
/// 创建Excel工作薄
/// </summary>
public void CreateExcel()
{
myExcel = new Application();
myWorkBook = myExcel.Application.Workbooks.Add(true);
} /// <summary>
/// 显示Excel
/// </summary>
public void ShowExcel()
{
myExcel.Visible = true;
} /// <summary>
/// 将数据写入Excel
/// </summary>
/// <param name="data">要写入的二维数组数据</param>
/// <param name="startRow">Excel中的起始行</param>
/// <param name="startColumn">Excel中的起始列</param>
public void WriteData(string[,] data, int startRow, int startColumn)
{
int rowNumber = data.GetLength();
int columnNumber = data.GetLength(); for (int i = ; i < rowNumber; i++)
{
for (int j = ; j < columnNumber; j++)
{
//在Excel中,如果某单元格以单引号“'”开头,表示该单元格为纯文本,因此,我们在每个单元格前面加单引号。
myExcel.Cells[startRow + i, startColumn + j] = "'" + data[i, j];
}
}
} /// <summary>
/// 将数据写入Excel
/// </summary>
/// <param name="data">要写入的字符串</param>
/// <param name="starRow">写入的行</param>
/// <param name="startColumn">写入的列</param>
public void WriteData(string data, int row, int column)
{
myExcel.Cells[row, column] = data;
} /// <summary>
/// 将数据写入Excel
/// </summary>
/// <param name="data">要写入的数据表</param>
/// <param name="startRow">Excel中的起始行</param>
/// <param name="startColumn">Excel中的起始列</param>
public void WriteData(System.Data.DataTable data, int startRow, int startColumn)
{
for (int i = ; i <= data.Rows.Count - ; i++)
{
for (int j = ; j <= data.Columns.Count - ; j++)
{
//在Excel中,如果某单元格以单引号“'”开头,表示该单元格为纯文本,因此,我们在每个单元格前面加单引号。
myExcel.Cells[startRow + i, startColumn + j] = "'" + data.Rows[i][j].ToString();
}
}
} /// <summary>
/// 读取指定单元格数据
/// </summary>
/// <param name="row">行序号</param>
/// <param name="column">列序号</param>
/// <returns>该格的数据</returns>
public string ReadData(int row, int column)
{
Range range = myExcel.get_Range(myExcel.Cells[row, column], myExcel.Cells[row, column]);
return range.Text.ToString();
} /// <summary>
/// 向Excel中插入图片
/// </summary>
/// <param name="pictureName">图片的绝对路径加文件名</param>
public void InsertPictures(string pictureName)
{
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
//后面的数字表示位置,位置默认
worksheet.Shapes.AddPicture(pictureName, MsoTriState.msoFalse, MsoTriState.msoTrue, , , , );
} /// <summary>
/// 向Excel中插入图片
/// </summary>
/// <param name="pictureName">图片的绝对路径加文件名</param>
/// <param name="left">左边距</param>
/// <param name="top">右边距</param>
/// <param name="width">宽</param>
/// <param name="heigth">高</param>
public void InsertPictures(string pictureName, int left, int top, int width, int heigth)
{
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
worksheet.Shapes.AddPicture(pictureName, MsoTriState.msoFalse, MsoTriState.msoTrue, top, left, heigth, width);
} /// <summary>
/// 向Excel中插入图片
/// </summary>
/// <param name="pictureName">图片的绝对路径加文件名</param>
/// <param name="left">左边距</param>
/// <param name="top">右边距</param>
/// <param name="width">宽</param>
/// <param name="heigth">高</param>
/// <param name="cell1">位置</param>
public void InsertPictures(string pictureName, int left, int top, int width, int heigth,object cell1) {
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range image1 = worksheet.get_Range(cell1, Missing.Value);
image1.Select();
worksheet.Shapes.AddPicture(pictureName, MsoTriState.msoFalse, MsoTriState.msoTrue, top, left, heigth, width);
} /// <summary>
/// 重命名工作表
/// </summary>
/// <param name="sheetNum">工作表序号,从左到右,从1开始</param>
/// <param name="newSheetName">新的工作表名</param>
public void ReNameSheet(int sheetNum, string newSheetName)
{
Worksheet worksheet = (Worksheet)myExcel.Worksheets[sheetNum];
worksheet.Name = newSheetName;
} /// <summary>
/// 重命名工作表
/// </summary>
/// <param name="oldSheetName">原有工作表名</param>
/// <param name="newSheetName">新的工作表名</param>
public void ReNameSheet(string oldSheetName, string newSheetName)
{
Worksheet worksheet = (Worksheet)myExcel.Worksheets[oldSheetName];
worksheet.Name = newSheetName;
} /// <summary>
/// 新建工作表
/// </summary>
/// <param name="sheetName">工作表名</param>
public void CreateWorkSheet(string sheetName)
{
Worksheet newWorksheet = (Worksheet)myWorkBook.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
newWorksheet.Name = sheetName;
} /// <summary>
/// 激活工作表
/// </summary>
/// <param name="sheetName">工作表名</param>
public void ActivateSheet(string sheetName)
{
Worksheet worksheet = (Worksheet)myExcel.Worksheets[sheetName];
worksheet.Activate();
} /// <summary>
/// 激活工作表
/// </summary>
/// <param name="sheetNum">工作表序号</param>
public void ActivateSheet(int sheetNum)
{
Worksheet worksheet = (Worksheet)myExcel.Worksheets[sheetNum];
worksheet.Activate();
} /// <summary>
/// 删除一个工作表
/// </summary>
/// <param name="SheetName">删除的工作表名</param>
public void DeleteSheet(int sheetNum)
{
((Worksheet)myWorkBook.Worksheets[sheetNum]).Delete();
} /// <summary>
/// 删除一个工作表
/// </summary>
/// <param name="SheetName">删除的工作表序号</param>
public void DeleteSheet(string sheetName)
{
((Worksheet)myWorkBook.Worksheets[sheetName]).Delete();
} /// <summary>
/// 合并单元格
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
public void CellsUnite(int startRow, int startColumn, int endRow, int endColumn)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.MergeCells = true;
} /// <summary>
/// 单元格文字对齐方式
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="hAlign">水平对齐</param>
/// <param name="vAlign">垂直对齐</param>
public void CellsAlignment(int startRow, int startColumn, int endRow, int endColumn, ExcelHAlign hAlign, ExcelVAlign vAlign)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.HorizontalAlignment = hAlign;
range.VerticalAlignment = vAlign;
} /// <summary>
/// 绘制指定单元格的边框
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
public void CellsDrawFrame(int startRow, int startColumn, int endRow, int endColumn)
{
CellsDrawFrame(startRow, startColumn, endRow, endColumn,
true, true, true, true, true, true, false, false,
LineStyle.连续直线, BorderWeight.细, ColorIndex.自动);
} /// <summary>
/// 绘制指定单元格的边框
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="isDrawTop">是否画上外框</param>
/// <param name="isDrawBottom">是否画下外框</param>
/// <param name="isDrawLeft">是否画左外框</param>
/// <param name="isDrawRight">是否画右外框</param>
/// <param name="isDrawHInside">是否画水平内框</param>
/// <param name="isDrawVInside">是否画垂直内框</param>
/// <param name="isDrawDown">是否画斜向下线</param>
/// <param name="isDrawUp">是否画斜向上线</param>
/// <param name="lineStyle">线类型</param>
/// <param name="borderWeight">线粗细</param>
/// <param name="color">线颜色</param>
public void CellsDrawFrame(int startRow, int startColumn, int endRow, int endColumn,
bool isDrawTop, bool isDrawBottom, bool isDrawLeft, bool isDrawRight,
bool isDrawHInside, bool isDrawVInside, bool isDrawDiagonalDown, bool isDrawDiagonalUp,
LineStyle lineStyle, BorderWeight borderWeight, ColorIndex color)
{
//获取画边框的单元格
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]); //清除所有边框
range.Borders[XlBordersIndex.xlEdgeTop].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlEdgeRight].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle = LineStyle.无;
range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle = LineStyle.无; //以下是按参数画边框
if (isDrawTop)
{
range.Borders[XlBordersIndex.xlEdgeTop].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlEdgeTop].Weight = borderWeight;
range.Borders[XlBordersIndex.xlEdgeTop].ColorIndex = color;
} if (isDrawBottom)
{
range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlEdgeBottom].Weight = borderWeight;
range.Borders[XlBordersIndex.xlEdgeBottom].ColorIndex = color;
} if (isDrawLeft)
{
range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlEdgeLeft].Weight = borderWeight;
range.Borders[XlBordersIndex.xlEdgeLeft].ColorIndex = color;
} if (isDrawRight)
{
range.Borders[XlBordersIndex.xlEdgeRight].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlEdgeRight].Weight = borderWeight;
range.Borders[XlBordersIndex.xlEdgeRight].ColorIndex = color;
} if (isDrawVInside)
{
range.Borders[XlBordersIndex.xlInsideVertical].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlInsideVertical].Weight = borderWeight;
range.Borders[XlBordersIndex.xlInsideVertical].ColorIndex = color;
} if (isDrawHInside)
{
range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlInsideHorizontal].Weight = borderWeight;
range.Borders[XlBordersIndex.xlInsideHorizontal].ColorIndex = color;
} if (isDrawDiagonalDown)
{
range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlDiagonalDown].Weight = borderWeight;
range.Borders[XlBordersIndex.xlDiagonalDown].ColorIndex = color;
} if (isDrawDiagonalUp)
{
range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle = lineStyle;
range.Borders[XlBordersIndex.xlDiagonalUp].Weight = borderWeight;
range.Borders[XlBordersIndex.xlDiagonalUp].ColorIndex = color;
}
} /// <summary>
/// 单元格背景色及填充方式
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="color">颜色索引</param>
public void CellsBackColor(int startRow, int startColumn, int endRow, int endColumn, ColorIndex color)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.Interior.ColorIndex = color;
range.Interior.Pattern = Pattern.Solid;
} /// <summary>
/// 单元格背景色及填充方式
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="color">颜色索引</param>
/// <param name="pattern">填充方式</param>
public void CellsBackColor(int startRow, int startColumn, int endRow, int endColumn, ColorIndex color, Pattern pattern)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.Interior.ColorIndex = color;
range.Interior.Pattern = pattern;
} /// <summary>
/// 设置行高
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="endRow">结束行</param>
/// <param name="height">行高</param>
public void SetRowHeight(int startRow, int endRow, int height)
{
//获取当前正在使用的工作表
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range range = (Range)worksheet.Rows[startRow.ToString() + ":" + endRow.ToString(), System.Type.Missing];
range.RowHeight = height;
} /// <summary>
/// 自动调整行高
/// </summary>
/// <param name="columnNum">列号</param>
public void RowAutoFit(int rowNum)
{
//获取当前正在使用的工作表
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range range = (Range)worksheet.Rows[rowNum.ToString() + ":" + rowNum.ToString(), System.Type.Missing];
range.EntireColumn.AutoFit(); } /// <summary>
/// 设置列宽
/// </summary>
/// <param name="startColumn">起始列(列对应的字母)</param>
/// <param name="endColumn">结束列(列对应的字母)</param>
/// <param name="width"></param>
public void SetColumnWidth(string startColumn, string endColumn, int width)
{
//获取当前正在使用的工作表
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range range = (Range)worksheet.Columns[startColumn + ":" + endColumn, System.Type.Missing];
range.ColumnWidth = width;
} /// <summary>
/// 设置列宽
/// </summary>
/// <param name="startColumn">起始列</param>
/// <param name="endColumn">结束列</param>
/// <param name="width"></param>
public void SetColumnWidth(int startColumn, int endColumn, int width)
{
string strStartColumn = GetColumnName(startColumn);
string strEndColumn = GetColumnName(endColumn);
//获取当前正在使用的工作表
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range range = (Range)worksheet.Columns[strStartColumn + ":" + strEndColumn, System.Type.Missing];
range.ColumnWidth = width;
} /// <summary>
/// 自动调整列宽
/// </summary>
/// <param name="columnNum">列号</param>
public void ColumnAutoFit(string column)
{
//获取当前正在使用的工作表
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range range = (Range)worksheet.Columns[column + ":" + column, System.Type.Missing];
range.EntireColumn.AutoFit(); } /// <summary>
/// 自动调整列宽
/// </summary>
/// <param name="columnNum">列号</param>
public void ColumnAutoFit(int columnNum)
{
string strcolumnNum = GetColumnName(columnNum);
//获取当前正在使用的工作表
Worksheet worksheet = (Worksheet)myExcel.ActiveSheet;
Range range = (Range)worksheet.Columns[strcolumnNum + ":" + strcolumnNum, System.Type.Missing];
range.EntireColumn.AutoFit(); } /// <summary>
/// 字体颜色
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="color">颜色索引</param>
public void FontColor(int startRow, int startColumn, int endRow, int endColumn, ColorIndex color)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.Font.ColorIndex = color;
} /// <summary>
/// 字体样式(加粗,斜体,下划线)
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="isBold">是否加粗</param>
/// <param name="isItalic">是否斜体</param>
/// <param name="underline">下划线类型</param>
public void FontStyle(int startRow, int startColumn, int endRow, int endColumn, bool isBold, bool isItalic, UnderlineStyle underline)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.Font.Bold = isBold;
range.Font.Underline = underline;
range.Font.Italic = isItalic;
} /// <summary>
/// 单元格字体及大小
/// </summary>
/// <param name="startRow">起始行</param>
/// <param name="startColumn">起始列</param>
/// <param name="endRow">结束行</param>
/// <param name="endColumn">结束列</param>
/// <param name="fontName">字体名称</param>
/// <param name="fontSize">字体大小</param>
public void FontNameSize(int startRow, int startColumn, int endRow, int endColumn, string fontName, int fontSize)
{
Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
range.Font.Name = fontName;
range.Font.Size = fontSize;
} /// <summary>
/// 打开一个存在的Excel文件
/// </summary>
/// <param name="fileName">Excel完整路径加文件名</param>
public void Open(string fileName)
{
myExcel = new Application();
myWorkBook = myExcel.Workbooks.Add(fileName);
myFileName = fileName;
} /// <summary>
/// 保存Excel
/// </summary>
/// <returns>保存成功返回True</returns>
public bool Save()
{
if (myFileName == "")
{
return false;
}
else
{
try
{
myWorkBook.Save();
return true;
}
catch (Exception ex)
{
return false;
}
}
} /// <summary>
/// Excel文档另存为
/// </summary>
/// <param name="fileName">保存完整路径加文件名</param>
/// <returns>保存成功返回True</returns>
public bool SaveAs(string fileName)
{
try
{
myWorkBook.SaveAs(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
return true; }
catch (Exception ex)
{
return false; }
} /// <summary>
/// 关闭Excel
/// </summary>
public void Close()
{
myWorkBook.Close(Type.Missing, Type.Missing, Type.Missing);
myExcel.Quit();
myWorkBook = null;
myExcel = null;
GC.Collect();
} /// <summary>
/// 关闭Excel
/// </summary>
/// <param name="isSave">是否保存</param>
public void Close(bool isSave)
{
myWorkBook.Close(isSave, Type.Missing, Type.Missing);
myExcel.Quit();
myWorkBook = null;
myExcel = null;
GC.Collect();
} /// <summary>
/// 关闭Excel
/// </summary>
/// <param name="isSave">是否保存</param>
/// <param name="fileName">存储文件名</param>
public void Close(bool isSave, string fileName)
{
myWorkBook.Close(isSave, fileName, Type.Missing);
myExcel.Quit();
myWorkBook = null;
myExcel = null;
GC.Collect();
} #region 私有成员
private string GetColumnName(int number)
{
int h, l;
h = number / ;
l = number % ;
if (l == )
{
h -= ;
l = ;
}
string s = GetLetter(h) + GetLetter(l);
return s;
} private string GetLetter(int number)
{
switch (number)
{
case :
return "A";
case :
return "B";
case :
return "C";
case :
return "D";
case :
return "E";
case :
return "F";
case :
return "G";
case :
return "H";
case :
return "I";
case :
return "J";
case :
return "K";
case :
return "L";
case :
return "M";
case :
return "N";
case :
return "O";
case :
return "P";
case :
return "Q";
case :
return "R";
case :
return "S";
case :
return "T";
case :
return "U";
case :
return "V";
case :
return "W";
case :
return "X";
case :
return "Y";
case :
return "Z";
default:
return "";
}
}
#endregion } /// <summary>
/// 水平对齐方式
/// </summary>
public enum ExcelHAlign
{
常规 = ,
靠左,
居中,
靠右,
填充,
两端对齐,
跨列居中,
分散对齐
} /// <summary>
/// 垂直对齐方式
/// </summary>
public enum ExcelVAlign
{
靠上 = ,
居中,
靠下,
两端对齐,
分散对齐
} /// <summary>
/// 线粗
/// </summary>
public enum BorderWeight
{
极细 = ,
细 = ,
粗 = -,
极粗 =
} /// <summary>
/// 线样式
/// </summary>
public enum LineStyle
{
连续直线 = ,
短线 = -,
线点相间 = ,
短线间两点 = ,
点 = -,
双线 = -,
无 = -,
少量倾斜点 =
} /// <summary>
/// 下划线方式
/// </summary>
public enum UnderlineStyle
{
无下划线 = -,
双线 = -,
双线充满全格 = ,
单线 = ,
单线充满全格 =
} /// <summary>
/// 单元格填充方式
/// </summary>
public enum Pattern
{
Automatic = -,
Checker = ,
CrissCross = ,
Down = -,
Gray16 = ,
Gray25 = -,
Gray50 = -,
Gray75 = -,
Gray8 = ,
Grid = ,
Horizontal = -,
LightDown = ,
LightHorizontal = ,
LightUp = ,
LightVertical = ,
None = -,
SemiGray75 = ,
Solid = ,
Up = -,
Vertical = -
} /// <summary>
/// 常用颜色定义,对就Excel中颜色名
/// </summary>
public enum ColorIndex
{
无色 = -,
自动 = -,
黑色 = ,
褐色 = ,
橄榄 = ,
深绿 = ,
深青 = ,
深蓝 = ,
靛蓝 = ,
灰色80 = ,
深红 = ,
橙色 = ,
深黄 = ,
绿色 = ,
青色 = ,
蓝色 = ,
蓝灰 = ,
灰色50 = ,
红色 = ,
浅橙色 = ,
酸橙色 = ,
海绿 = ,
水绿色 = ,
浅蓝 = ,
紫罗兰 = ,
灰色40 = ,
粉红 = ,
金色 = ,
黄色 = ,
鲜绿 = ,
青绿 = ,
天蓝 = ,
梅红 = ,
灰色25 = ,
玫瑰红 = ,
茶色 = ,
浅黄 = ,
浅绿 = ,
浅青绿 = ,
淡蓝 = ,
淡紫 = ,
白色 =
}
ExcelHelper类的更多相关文章
- 【转】ExcelHelper类,用npoi读取Excel文档
//------------------------------------------------------------------------------------- // All Right ...
- ExcelHelper office 导出
要是服务器上没有装着excel 可以用c#导出excel表吗 2009-08-10 17:36 风之成 | 分类:办公软件 | 浏览2279次 租用的空间 服务器上没有装着office excel,可 ...
- Python Excel工具类封装, 给excel表头搞点颜色
封装Excel工具类 我们常用的excel工具类,读有xlrd,写有xlwt.有读有写,新一代库有pandas,openpyxl等等. 大家用法都差不多,今天博主就介绍新手最爱,我也爱的xlrd和xl ...
- Java类的继承与多态特性-入门笔记
相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...
- 使用NPOI组件完成的Excel导出导入(附源代码,测试通过)
最近遇到一个Excel导入导出的问题,要支持winform和webform,这里我是一个认真严谨的coder,所以决定把这个记录下来!和大家一起分享一下!如果需要的同学可以下载哦! 对于NPOI这个组 ...
- 使用NPOI读取Excel到DataTable
一.NPOI介绍: 使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写.NPOI是构建在POI 3.x版本之上的,它可以在没有安装Office ...
- C#操作Excel的函数
对于Excel的数据处理功能,大家都已经了解. 我们经常需要将数据导入到Excel,或直接打开Excel文档,读写文件操作,这需要用到ExcelHelper类,有了这个类,这些操作大大的减少我们工作量 ...
- NPOI读写Excel
1.整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表):Sheet:行:Row:单元格Cell. 2.NPOI是POI的C#版本,NPOI的行和列的index都是从0开始 ...
- C#Excel的导入与导出
1.整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表):Sheet:行:Row:单元格Cell. 2.NPOI是POI的C#版本,NPOI的行和列的index都是从0开始 ...
随机推荐
- BZOJ-3679(数位DP)
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a,b; int k[20]; ll dp[2 ...
- LeetCode945-使数组唯一的最小增量
问题:使数组唯一的最小增量 给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1. 返回使 A 中的每个值都是唯一的最少操作次数. 示例 1: 输入:[1,2,2] 输出:1 ...
- python入门:输出1-100之内的所有奇数和偶数
#!/usr/bin/env python # -*- coding:utf-8 -*- #输出1-100之内的所有奇数和偶数 """ 给start赋值等于1,while ...
- C# NotifyIcon 托盘控件
右下角以图标形式显示,双击图标显示界面,最小化界面时不显示在任务栏. 第一步:在界面上添加NotifyIcon控件. 第二步:设置notifyIcon1的属性,添加图标,将Visible设为true. ...
- python基本操作(五)
if 判断 if 条件: 代码1 代码2 代码3 代码块(同一缩进级别的代码,例如代码1.代码2和代码3是相同缩进的代码,这三个代码组合在一起就是一个代码块,相同缩进的代码会自上而下的运行) cls ...
- python-numpy-pandas
目录 numpy 模块 创建矩阵方法: 获取矩阵的行列数 切割矩阵 矩阵元素替换 矩阵的合并 通过函数创建矩阵 矩阵的运算 pandas模块 series (一维列表) DataFrame DataF ...
- 嵌入式入门学习笔记3:[转]编译linux
摘自:https://blog.csdn.net/baidu_24256693/article/details/80115354 编译Linux是什么意思? Linux内核是Linux操作系统的核心, ...
- 关于sizeof,对空指针sizeof(*p)可以吗?
C/C++的sizeof在动态分配内存时经常用到,但之前一直没怎么关注它的具体机制.今天在为一个复杂声明的指针分配内存时,想起来要了解一下sizeof到底是什么? 先抛个问题: 程序运行过程中对空指针 ...
- 令人惊叹的Chrome浏览器插件
Chrome是一个简洁而又高效(高性能,高消耗)的浏览器.接下来让我吐血推荐一些常用的Chrome插件. 日常插件 uBlock Origin ----- 比Adblock性能更高的广告插件. Adk ...
- Selenium WebDriver-获取与切换浏览器窗口的句柄
通过selenium webdriver去切换浏览器的窗口,需要通过句柄,具体代码如下: #encoding=utf-8 import unittest import time import char ...