tab 1
此 demo 展示如何将 excel 文档 (xls/xlsx) 转换为 pdf、html 和图片格式。
如果这不是您想要的 demo,您可以通过填写表格获取免费定制 demo。
如您有与我们产品相关的其他技术问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。;销售相关的问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。。
tab 2
using system;
using spire.xls;
using system.drawing;
using system.drawing.imaging;
namespace demoonlinecode
{
class convertors
{
public void democonvert(string filepath, string format,string resultfilename)
{
workbook book = new workbook();
book.loadfromfile(filepath) ;
convertformat(book, format, resultfilename);
}
private void convertformat(workbook workbook, string format, string resultfilename)
{
switch (format)
{
case "pdf":
workbook.savetofile(resultfilename ".pdf", spire.xls.fileformat.pdf);
break;
case "image":
image[] images = new image[workbook.worksheets.count];
for (int i = 0; i < workbook.worksheets.count; i )
{
images[i] = workbook.saveasimage(i, 96, 96);
}
if (images != null && images.length > 0)
{
if (images.length == 1)
{
images[0].save(resultfilename ".bmp", system.drawing.imaging.imageformat.bmp);
}
else
{
for (int i = 0; i < images.length; i )
{
string filename = string.format("{0}-image-{1}.png", resultfilename, i);
images[i].save(filename, imageformat.png);
}
}
}
break;
case "html":
for (int i = 0; i < workbook.worksheets.count; i )
{
worksheet sheet = workbook.worksheets[i];
string htmlpath = string.format(resultfilename "-{0}.html", i );
sheet.savetohtml(htmlpath);
}
break;
}
}
}
}
tab 3
imports spire.xls
imports system.drawing
imports system.drawing.imaging
namespace demoonlinecode
class convertors
public sub democonvert(filepath as [string], format as string, resultfilename as string)
dim book as new workbook()
book.loadfromfile(filepath)
convertformat(book, format, resultfilename)
end sub
private sub convertformat(workbook as workbook, format as string, resultfilename as string)
select case format
case "pdf"
workbook.savetopdf(resultfilename & ".pdf", spire.xls.fileformat.pdf)
exit select
case "image"
dim images as image() = new image(workbook.worksheets.count - 1) {}
for i as integer = 0 to workbook.worksheets.count - 1
images(i) = workbook.saveasimage(i, 96, 96)
next
if images isnot nothing andalso images.length > 0 then
if images.length = 1 then
images(0).save(resultfilename & ".bmp", system.drawing.imaging.imageformat.bmp)
else
for i as integer = 0 to images.length - 1
dim filename as [string] = [string].format("{0}-image-{1}.png", resultfilename, i)
images(i).save(filename, imageformat.png)
next
end if
end if
exit select
case "html"
for i as integer = 0 to workbook.worksheets.count - 1
dim sheet as worksheet = workbook.worksheets(i)
dim htmlpath as string = string.format(resultfilename & "-{0}.html", system.math.max(system.threading.interlocked.increment(i), i - 1))
sheet.savetohtml(htmlpath)
next
exit select
end select
end sub
end class
end namespace