Aspose下载图片
/// <summary>
/// 把DataTable数据按照Excel模板导出到Excel
/// </summary>
/// <param name="templateFileName">模板名称</param>
/// <param name="fileName">Excel文件路径</param>
/// <param name="ds">DataSet</param>
/// <returns></returns>
public static BatchDownloadResponse DataTableToExcel(string templateFileName, string fileName, DataSet ds)
{
if (!string.IsNullOrEmpty(templateFileName)) templateFileName = templateFileName.Replace("\\\\", "\\");
if (!string.IsNullOrEmpty(fileName)) fileName = fileName.Replace("\\\\", "\\");
BatchDownloadResponse response = new BatchDownloadResponse(fileName);
if (ds == null || ds.Tables.Count == 0)
{
response.AddError(0, "Data is empty, check the file!");
return response;
}
string licPath = System.Configuration.ConfigurationManager.AppSettings["AsposeLicPath"];
License lic = new License();
if (!string.IsNullOrEmpty(licPath)) lic.SetLicense(licPath);
WorkbookDesigner wd = new WorkbookDesigner();
wd=new WorkbookDesigner(new Workbook(templateFileName));
wd.SetDataSource(ds);
//wd.SetDataSource("GEO", "GEO");
//wd.SetDataSource("Product Group", "Product Group");
//wd.SetDataSource("Product Series", "Product Series");
//wd.SetDataSource("Product Family", "Product Family");
//wd.Workbook.Worksheets[0].Cells.DeleteColumn(1,true);
wd.Process();
wd.Workbook.CalculateFormula();
wd.Workbook.Save(fileName, SaveFormat.Xlsx);
wd = null;
FileInfo fi = new FileInfo(fileName);
response.FileName = fi.Name;
return response;
}
switch (productGroup)
{
case "NOTEBOOK":
productGroup= "NB";
break;
}
List<byte> result = new List<byte>();
string filePath = string.Format(@"{0}\Documents\TempFolder\PriceCable_Download_{1}.xlsx", HttpContext.Current.Request.PhysicalApplicationPath, DateTime.Now.ToString("yyyyMMddhhmmss"));
AsposeHelper.DataTableToExcel(templateFileName, filePath, ds);
Workbook workbook = new Workbook(filePath);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = productGroup.Replace("/", "");// + "Price cable";
int picIndex = sheet.Pictures.Add(0, 1, 3, 3, imagefilePath);
Aspose.Cells.Drawing.Picture pic = sheet.Pictures[picIndex];
pic.HeightCM = 1.3;
int linkIndex = sheet.Hyperlinks.Add("D7", 1, 1, "'Terms & Conditions'!A1");
Hyperlink hyperLink = sheet.Hyperlinks[linkIndex];
hyperLink.ScreenTip = "'Terms & Conditions'!A1";
hyperLink.TextToDisplay = "Pls refer to \"Terms & Conditions\" tab (click here)";
if (sheetName.Trim() != null && sheetName != "")
{
workbook.Worksheets[sheetName].IsVisible = true;
workbook.Worksheets[sheetName].Name = "MOQ";
sheetName = "MOQ";
int linkIndex2 = sheet.Hyperlinks.Add("D8", 1, 1, "\'" + sheetName + "\'!A1");
Hyperlink hyperLink2 = sheet.Hyperlinks[linkIndex2];
hyperLink2.ScreenTip = "'" + sheetName + "'!A1";
hyperLink2.TextToDisplay = "Pls refer to \"MOQ\" tab (click here)";
}
else {
//sheet.AutoFitRows(7, 8);
int linkIndex2 = sheet.Hyperlinks.Add("B8", 1, 1, "");
Hyperlink hyperLink2 = sheet.Hyperlinks[linkIndex2];
hyperLink2.TextToDisplay = "";
}
workbook.Worksheets.ActiveSheetIndex = 0;
Cells cells = sheet.Cells;
DataTable dt = ds.Tables[1];
int index = 14;
int[] centerCollection = new int[] { 1, 2, 3, 11, 12,13,14,15 };
int[] rightCollection = new int[] { 5, 6, 7, 8, 9, 10 };
CellValueFormatStrategy format = new CellValueFormatStrategy();
string split = @"
";
string descriptionValue = "";
string[] descriptionLines;
foreach (DataRow dr in dt.Rows)
{
if (dr["IsSeries"].ToString() == "1")
{
for (int i = 1; i < 16; i++)
{
cells[index, i].SetStyle(GetCellStyle(workbook, "bgSeries"));
}
}
else if (dr["IsFamily"].ToString() == "1")
{
for (int i = 1; i < 16; i++)
{
cells[index, i].SetStyle(GetCellStyle(workbook, "bgFamily"));
}
}
else
{
for (int i = 1; i < 16; i++)
{
string styleTemp = "";
switch (dr["ItemTypeHidden"].ToString())
{
case "0":
styleTemp = "bgText";
break;
case "1":
styleTemp = "bgBundle";
break;
case "2":
styleTemp = "bgOption";
break;
}
if (centerCollection.Contains(i))
{
if (i == 5 || i == 7 || i == 9 || i == 10)
{
cells[index, i].SetStyle(GetCellStyle(workbook, styleTemp + "CenterInteger"));
}
else
{
cells[index, i].SetStyle(GetCellStyle(workbook, styleTemp + "Center"));
}
}
else if (rightCollection.Contains(i))
{
if (i == 6 || i == 8)//这两列是百分比显示
{
styleTemp = styleTemp + "CenterPercent";
}
else if (i == 5 || i == 7 || i == 9 || i == 10)
{
styleTemp = styleTemp + "CenterInteger";
}
else
{
styleTemp = styleTemp + "CenterInteger";
}
cells[index, i].SetStyle(GetCellStyle(workbook, styleTemp));
}
else if (i == 13)
{
cells[index, i].SetStyle(GetCellStyle(workbook, styleTemp + "CenterRed"));
}
else if (i == 4)
{
cells[index, i].SetStyle(GetCellStyle(workbook, styleTemp + "Left"));//先设置Description列左对齐
//设置自动行高
AutoFitterOptions option = new AutoFitterOptions() { AutoFitMergedCells = false, OnlyAuto = true, IgnoreHidden = false };
sheet.AutoFitRows(index, index + 1, option);
descriptionValue = cells[index, i].GetStringValue(format);//获取Description列的值
if (descriptionValue.Length < 1)
{
continue;//如果Description为空,就结束此次循环
}
descriptionLines = descriptionValue.Split(new string[] { split }, StringSplitOptions.None);
if (descriptionLines.Length > 1)
{
//如果Description为多行,就自定义设置行高,将会覆盖刚才的自动行高
double lineHight = descriptionLines.Length * 15;
cells.SetRowHeight(index, lineHight);
}
}
}
}
index++;
}
if(CountryCode.ToUpper()!= "SINGAPORE")
{
cells.HideColumn(14);
}
workbook.Save(filePath);
return filePath;
Aspose下载图片的更多相关文章
- C++根据图片url下载图片
需要使用到URLDownloadToFile()函数,该函数在头文件<urlmon.h>中声明. URLDownloadToFile()函数的定义如下: HRESULT URLDownlo ...
- .net 已知图片的网络路径,通过浏览器下载图片
没什么技术含量,主要留给自己查找方便: 如题,知道图片的完整网络路径的情况下,在浏览器中下载图片的实现: 下面这个方法实现的是把图片读取为byte数组: private byte[] GetImage ...
- (TODO:)下载图片,报错:warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
想使用NSInvocationOperation下载图片,然而并没有下载下来, NSData为nil, 还有报错:(打断点就报错) warning: could not load any Object ...
- Android 本地/网路下载图片实现放大缩小
Android 本地加载/网路下载图片实现放大缩小拖拉效果,自定义控件. package com.example.ImageViewCustom; import android.app.Activi ...
- 利用node来下载图片到本地
本文是针对于知道图片地址的下载图片方法. 同时也是我的处男作(额,怪怪的〜);不要在意这些细节. 最近在弄项目迁移,需要把http的链接全换成https的:以前的cms不支持http的协议,然后就 ...
- SDWebImage下载图片有时候无法成功显示出来
之前用下面的方法现在图片,有时候会出现图片没有下载成功显示: - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)p ...
- 根据url地址单个或批量下载图片
我们在java开发的时候会遇到通过url地址下载图片的情况.方便起见,我把通过url地址下载图片封装了tool工具类,方便以后使用 1.根据如:http://abc.com/hotels/a.jpg ...
- 使用HttpURLConnection下载图片
import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.Ht ...
- Android下载图片/调用系统相机拍照、显示并保存到本地
package com.example.testhttpget; import java.io.BufferedReader; import java.io.FileNotFoundException ...
随机推荐
- Asp.Net Core入门之自定义服务注册
谈到服务注册,首先我们先了解一下服务注册时使用的三种方式,也代表了不同的服务生命周期: AddTransient AddScoped AddSingleton AddSingleton生命周期最长,其 ...
- 04 . Docker安全与Docker底层实现
Docker安全 Docker安全性时,主要考虑三个方面 # 1. 由内核的名字空间和控制组机制提供的容器内在安全 # 2. Docker程序(特别是服务端)本身的抗攻击性 # 3. 内核安全性的加强 ...
- foreach 集合又抛经典异常了,这次一定要刨根问底
一:背景 1. 讲故事 最近同事在写一段业务逻辑的时候,程序跑起来总是报:集合已修改:可能无法执行枚举操作,硬是没有找到什么情况下会导致这个异常产生,就让我来找一下bug,其实这个异常在座的每个程序员 ...
- 用turtle画蛇
import turtle def drawSnake(rad,angle,len,nackrad): for i in range(len): turtle.circle(rad,angle) #画 ...
- 动作函数-web_custom_request
web_custom_request("get_login", "URL=http://10.1.102.75:8000/login?user=Milton&pw ...
- [CentOS 7]挂载ntfs格式U盘
在我们将U盘插入装有CentOS的系统时,经常会出现如图所示的错误提示.这是因为linux系统并不能兼容NTFS的文件系统.其解决方法如下(建议先进入root模式): 1.首先下载"ntfs ...
- 查看apk安装包信息
➜ sdk aapt dump badging ~/Downloads/PermRoot8006.apk package: name='com.qihoo.permmgr' versionCode=' ...
- #PHP 类的多继承实现之 traits.md
TRAIT PHP本身是并不支持多继承的,也就是,一个类只能继承一个类,为了满足业务需求,后来有了一些解决方法,例如,链式继承,B继承A,然后C继承B,这样,C就同时继承了AB, 此外还有接口,因为接 ...
- 00【笔记】 Shiro登陆过滤提示信息
Shiro登陆过滤 提示信息 package top.yangbuyi.system.shiro; import com.alibaba.fastjson.JSONObject; import org ...
- JS判断 函数是否定义/变量是否定义
函数是否定义: <script type="text/javascript"> try { if(typeof FunName === "function&q ...