[轉]c#从Excel中读取图片
生活随笔
收集整理的這篇文章主要介紹了
[轉]c#从Excel中读取图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
From : http://hi.baidu.com/o0o%CD%F5%D4%F3%C3%F1o0o/blog/item/e311bf252bdf4d3b8644f95f.html
?
private string exclePath = @"E:\111.xls";private int StartRow = 2; //讀的起始行
private void button1_Click(object sender, System.EventArgs e)
{
Excel.Application excel = new Excel.Application();//引用Excel對象
Excel.Workbook workbook = excel.Workbooks.Add(exclePath);
excel.UserControl = true;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
excel.Visible = false;
for (int i = 0; i < workbook.Worksheets.Count; i++)//循環取所有的Sheet.
{
Excel.Worksheet sheet = workbook.Worksheets.get_Item(i + 1) as Excel.Worksheet;//從1開始.
for (int row = StartRow; row <= sheet.UsedRange.Rows.Count; row++)
{
//取單元格值;
for (int col = 1; col <= sheet.UsedRange.Columns.Count; col++)
{
Excel.Range range =sheet.Cells[row, col] as Excel.Range;
sb.Append("," + col.ToString() + ":" + range.Text);
}
sb.Append(System.Environment.NewLine);
//取存圖片;
if(sheet.Shapes.Count > row - StartRow )
{
Excel.Shape s = sheet.Shapes.Item(row - StartRow + 1) as Excel.Shape;
s.CopyPicture(Appearance.Button, Excel.XlCopyPictureFormat.xlBitmap); //COPY到內存。
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Bitmap))
{
pictureBox1.Image = (Bitmap)iData.GetData(DataFormats.Bitmap); //從內存取值;
pictureBox1.Image.Save(string.Format(@"D:\{0}.jpg", row)); //保存。
}
else
{
pictureBox1.Image = null;
}
}
}
}
workbook.Close(false,null,null);
excel.Quit();
}
?
總結
以上是生活随笔為你收集整理的[轉]c#从Excel中读取图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [笔记] 分频计数(七)
- 下一篇: win 7 系统激活工具