cs:(上传文件并将Excel中的内容导入到数据库中)
public JsonResult DoImport(string uploadtype, string q_t)
{
iPAL.Applications.Authen.LoginUser user = (iPAL.Applications.Authen.LoginUser)(Session["LoginUser"]);
m_userno = user.WorkNo;
AjaxCallResult result = new AjaxCallResult();
HttpContext.Response.ContentType = "text/plain";
HttpContext.Response.Charset = "utf-8";
string msg = string.Empty;
string strUploadPath = HttpContext.Request.PhysicalApplicationPath + "iPALUploads\\";
try
{
if (!Directory.Exists(strUploadPath))
{
Directory.CreateDirectory(strUploadPath);
}
if ( HttpContext.Request.Files.Count != 1 )
{
result.result = -1;
result.data = "上传文件只能为1.";
return Json(result);
}
HttpPostedFileBase postedFile = HttpContext.Request.Files[0];
string fileName = postedFile.FileName;
string ext = fileName.Substring(fileName.LastIndexOf('.'));
string tempFile = fileName.Substring(0,fileName.Length - ext.Length -1 ) + Guid.NewGuid().ToString("N");
tempFile = Path.Combine(strUploadPath, tempFile) + ext;
postedFile.SaveAs(tempFile);
result.result = ImportSheet(tempFile, q_t, m_userno, ref msg);
result.data = msg;
}
catch (Exception ex)
{
result.result = -1;
result.data = ex.Message;
}
return Json(result);
}
private int ImportSheet(string filePath,string bigT,string userno,ref string msg)
{
ExcelReader excel = new ExcelReader();
DataTable dt = new DataTable();
int nRet = 0;
List<BIGT_SHEET_MODEL> lstSheet = btModuel.GetSheetModel();//sheet
List<BIGT_SHEET_MODEL> lstColModel = btModuel.GetColModel();//列模型
List<BigTColModel> lstCol = new List<BigTColModel>();
BIGT_SHEET_MODEL col;
BIGT_SHEET_MODEL sheet;
int nFailSheet = 0;
for( int i=0; i < lstSheet.Count;i++)
{
sheet = lstSheet[i];
if (excel.ReadFromExcel(filePath, sheet.sheet_name, dt) < 0)
{
nFailSheet++;
if (nFailSheet == lstSheet.Count)
{
msg = "没有发现任何可识别Sheet名";
return -1;
}
continue;
}
//获取列模型
lstCol.Clear();
for (int k = 0; k < lstColModel.Count; k++)
{
col = lstColModel[k];
if (string.IsNullOrEmpty(col.col_index))//只取与数据库对应的列
{
continue;
}
if (string.IsNullOrEmpty(col.col_model) || sheet.col_model == col.col_model)
{
BigTColModel colModel = new BigTColModel();
colModel.sheet_name = col.sheet_name;
colModel.col_index = col.col_index;
lstCol.Add(colModel);
}
else
{
continue;
}
}
nRet = ImportSheetData(userno, sheet.sheet_name, bigT, dt, lstCol, ref msg);
if (nRet < 0)
{
return -1;
}
}
return 1;
}
分享到:
相关推荐
uploadfy(上传文件插件),用于同时上传多个文件
这是一个uploadfy上传插件,非常好用,美观。
uploadfy+easyui+struts+json文件上传 ...其中只在action中模拟接收文件,存储文件到指定目录,但是没有跟数据库打交道。 但是这个跟数据库打交道的问题,大家很容易解决了。无论SSH还是SSI还是什么的
uploadfy插件.net源码实例,包含下载的uploadfy插件,对于上传文件图片有很好的帮助
最近在公司进行项目开发时使用的一个上传小东西,很好用。分享给大家。
支持文件批量上传,单个上传,并返回是否上传成功
asp.net利用jquery的uploadfy插件上传图片,我自己编辑的好用。
uploadfy批量上传,图片、视频。带非常漂亮的进度条
uploadfy实现无刷新上传,下载即可直接运行。
uploadfy 上传文件插件,flash的
java版本uploadfy实现上传,下载下来直接部署在tomcat下访问就行,一般不会有问题
这是根据uploadify3 2结合struts2搭建的文件上传环境 可以直接导入eclipse运行 每步实现基本都加了注释 以下是我碰到的问题: 1 判断session是否失效 本实例没测试这个问题 但在工作项目中碰到了 但原因在这里...
实现图片批量无刷新上传与批量浏览功能。
unigui_swfupload批量文件上传.zip
NULL 博文链接:https://gzuimis.iteye.com/blog/1463505
Uploadify简单说来,是基于Jquery的一款文件上传插件。它的功能特色总结如下: 支持单文件或多文件上传,可控制并发上传的文件数 在服务器端支持各种语言与之配合使用
利用 jquery uploadify + java 做的批量上传的例子,可以直接运行
基于jquery.uploadify封装的自定义控件,支持简单引用就能被使用,有源码,控件配置简单。上传文件后可显示文件图标。
次压缩包除官方所提供的uploadify3.2包含文件外,还有JQUERY的基础库(jquery-1.8.0.min.js),以及(swfobject.js)组件,这两个文件在使用uploadify3.2组件时也是必须引入的,为了方便,所以将其都压缩到一起,供...