using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Spire.Xls;
using System.IO;
using System.Drawing;
public void xlzs()
{
string activeDir = System.AppDomain.CurrentDomain.BaseDirectory;
string newPath = System.IO.Path.Combine(activeDir, "images");
System.IO.Directory.CreateDirectory(newPath);
Workbook wb = new Workbook();
wb.LoadFromFile("D:/exc/b1.xls");
Worksheet sheet = wb.Worksheets[0];
ExcelPicture picture = sheet.Pictures[0];
picture.Picture.Save(newPath + "/ExtractedImg.png");
string connStr = System.Configuration.ConfigurationManager.AppSettings["oasys"].ToString();
SqlConnection sqlConnection2 = new SqlConnection(connStr);
sqlConnection2.Open();
string dz = newPath + "/ExtractedImg.png";
byte[] im = GetPictureData(dz);
string sql = "insert into xlzs(sfz,xl_image) values ('222','@Image')";
SqlCommand sqlCommand11 = new SqlCommand(sql, sqlConnection2);
sqlCommand11.Parameters.Add("@Image", SqlDbType.Image);
sqlCommand11.Parameters["@Image"].Value = im;
sqlCommand11.ExecuteNonQuery();
sqlConnection2.Close();
DeleteImgFile(newPath + "/ExtractedImg.png");
public byte[] GetPictureData(string imagepath)
{
FileStream fs = new FileStream(imagepath, FileMode.Open);
byte[] byData = new byte[fs.Length];
fs.Read(byData, 0, byData.Length);
fs.Close();
return byData;
}
public static void DeleteImgFile(string fileUrl)
{
if (System.IO.File.Exists(fileUrl))
{
System.IO.File.Delete(fileUrl);
}
}