public class ExcelHelper
{
/// <summary>
/// 根據(jù)html模板文件生成excel文件
/// </summary>
/// <param name="ds">數(shù)據(jù)源</param>
/// <param name="TemplateFilePath">html模板文件路徑(虛擬路徑而非物理路徑)</param>
/// <param name="ToFileName">生成的excel文件名,帶后綴不帶路徑</param>
/// <returns></returns>
public static string GetExcel(DataSet ds, string TemplateFilePath, string ToFileName)
{
string ToFilePath=SysHelper.GetVirtualPath() + "upload/export_excel/";
string strOutPath=HttpContext.Current.Server.MapPath(ToFilePath);
if (!Directory.Exists(strOutPath))
{
Directory.CreateDirectory(strOutPath);
}
string TemplateContent=GetStringFromTemplate(ds, TemplateFilePath);
//保存文件
using (FileStream fs=new FileStream(strOutPath + ToFileName, FileMode.Create))
{
using (StreamWriter sw=new StreamWriter(fs))
{
sw.Write(TemplateContent);
}
}
return ToFilePath + ToFileName;
}
/// <summary>
/// 根據(jù)模板生成字符換
/// </summary>
/// <param name="ds"></param>
/// <param name="TemplateFilePath"></param>
/// <returns></returns>
private static string GetStringFromTemplate(DataSet ds, string TemplateFilePath)
{
//讀取模板
string TemplateContent="";
using (StreamReader sr=new StreamReader(HttpContext.Current.Server.MapPath(TemplateFilePath)))
{
TemplateContent=sr.ReadToEnd();
}
//解析每個表
for (int TableIndex=0; TableIndex < ds.Tables.Count; TableIndex++)
{
DataTable dt=ds.Tables[TableIndex];
//獲取表的模板集合
string TableTag=string.Format(@"#table.{0}#", TableIndex);//表的標簽
string pattern=string.Format(@"#table\.{0}#.*?#table\.{0}#", TableIndex);
Regex reg=new Regex(pattern, RegexOptions.Singleline);
MatchCollection matchs=reg.Matches(TemplateContent);
//解析每個模板
foreach (Match match in matchs)
{
string tableTemplate=match.Value;
string table="";//解析后內容
//解析每行數(shù)據(jù)
for (int i=0; i < dt.Rows.Count; i++)
{
string rowTemplate=tableTemplate.Replace(TableTag, "");//去掉模板標簽
//解析行模板
for (int j=0; j < dt.Columns.Count; j++)
{
string ColumnName="#table." + TableIndex + "." + dt.Columns[j].ColumnName + "#";
rowTemplate=rowTemplate.Replace(ColumnName, dt.Rows[i][j].ToString());
}
table +=rowTemplate;
}
//解析完之后替換到模板
TemplateContent=TemplateContent.Replace(tableTemplate, table);
}
}
return TemplateContent;
}
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<table border="1">
<tr>
<td colspan="4" style="text-align:center;">事件匯總表</td</tr>
<tr>
<td style="width:200px;">事件名稱</td>
<td style="width:500px;">事件簡要情況</td>
<td style="width:100px;">發(fā)生時間</td>
<td style="width:100px;">發(fā)生地區(qū)</td>
</tr>
#table.0#
<tr>
<td>#table.0.omtb_title#</td>
<td>#table.0.omtb_content#</td>
<td>#table.0.omtb_date#</td>
<td>#table.0.omtb_address#</td>
</tr>
#table.0#
</table>
</body>
</html>
string templatepath=SysHelper.GetVirtualPath() + "zfb/pro_list_excel.html",
outfile="事件匯總表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
string excel_file_path=ExcelHelper.GetExcel(dsSource, templatepath, outfile);
附加獲取應用程序虛擬目錄方法
pire.XLS for Java 13.3.6 已發(fā)布。本次更新支持將Excel轉換為獨立的HTML文件,支持了保存整個Excel到HTML流,支持了給透視表的透視域字段(PivotFields)和數(shù)據(jù)域字段(DataFields)添加條件格式,并且支持取代一個單元格內部分文本的功能。同時,該版本還Excel 到 PDF和圖片的轉換。此外,一些已知問題也得到了修復,如修復了轉換圖表到圖片時引導線丟失的問題。詳情請閱讀以下內容。
新功能:
Workbook wb=new Workbook();
wb.loadFromFile("data/mytest.xlsx");
HTMLOptions.Default.isStandAloneHtmlFile(true);
wb.saveToFile("result.html", FileFormat.HTML);
Workbook wb=new Workbook();
wb.loadFromFile("data/mytest.xlsx");
FileOutputStream fileStream=new FileOutputStream("output/saveStream_result.html");
wb.saveToStream(fileStream, FileFormat.HTML);
fileStream.close();
PivotTable table=(PivotTable)worksheet.getPivotTables().get(0);
PivotConditionalFormatCollection pcfs=table.getPivotConditionalFormats();
PivotConditionalFormat pc=pcfs.addPivotConditionalFormat(table.getColumnFields().get(0));
//PivotConditionalFormat pc=pcfs.addPivotConditionalFormat(table.getRowFields().get(0));
//PivotConditionalFormat pc=pcfs.addPivotConditionalFormat(table.getDataFields().get(0));
//PivotConditionalFormat pc=pcfs.addPivotConditionalFormat(table.getPageFields().get(0));
IConditionalFormat cf=pc.addCondition();
cf.setFormatType(ConditionalFormatType.ContainsBlanks);
cf.setFillPattern(ExcelPatternType.Solid);
cf.setBackColor(Color.Red);
sheet.getCellList().get(0).textPartReplace("Office", "Spire");
問題修復:
下載Spire.XLS for Java 13.3.6請點擊:
Spire.XLS for Java | 下載
ord、Excel、PPT是我們平時辦公中經(jīng)常用到的幾款軟件,它可以適應我們不同的日常需要,為我們提供高效便捷的操作體驗。
但是,大部分人其實苦于文件格式的相互轉化,不知道office軟件的隱藏的操作技巧,也常因為沒有掌握操作技巧而浪費了許多時間。
今天,小編就教大家如何實現(xiàn)Word、Excel、PPT文件之間格式的相互轉化,無需下載其他軟件,只需20秒,輕松完成文件格式的相互轉化!
Excel轉word只需要兩步操作。
首先,我們將表格的內容復制下來,然后打開Word。
按下【Ctrl+Alt+V】,接著選擇【Microsoft Excel工作表對象】,最后點擊確定,表格就轉換成Word了。
在將Excel轉化為PPT的時候,我們既要將內容完整復制到PPT界面中,又不能影響Excel表格的原始格式。
首先,我們復制Excel表格并打開PPT文稿界面;
點擊【開始】菜單下的【選擇性粘貼】,選擇【Mirosoft Excel工作表對象】,點擊確定;
選擇插入的表格,雙擊鼠標左鍵就可以進入編輯狀態(tài)啦!你也可以根據(jù)自己的需要通過拖拉邊框對插入的表格大小進行調整,以適應PPT演示文稿所容納的界面。
在將Word轉化為Excel時,我們不能直接復制,而需要先將word改為網(wǎng)頁格式,再轉換成表格。
先打開word,然后文件—另存為—保存類型改為網(wǎng)頁,即 Html。
接著新建表格,將保存好的網(wǎng)頁文件拖拽到Excel中,最后選擇只讀即可完成轉化。
除了鼠標右鍵復制粘貼之外,辦公中我們經(jīng)常遇到的問題是,如何按照文檔大綱將其分頁轉化到PPT界面。其實只需要簡單幾步就能完成。
首先打開word文檔,然后點擊【視圖】菜單下的【大綱】分別將標題和正文內容設置為1級和2級內容。
設置好大綱后,點擊右上角的【文件】→【選項】,在彈窗中選擇【快速訪問工具欄】,然后在右邊找到【發(fā)送Microsoft PowerPoint】并將其添加到功能區(qū)中,如下圖所示。
添加完成后,回到大綱界面,點擊頂部的電腦圖標,word會將文檔發(fā)送到PPT中,這樣word就變成PPT。
以上就是今天分享的內容了,其實Word、Excel、PPT之間的格式轉化非常簡單,只要簡單幾步,就能一鍵輕松轉換。
歡迎大家在評論中與我們分享其他好用的電腦技巧。
*請認真填寫需求信息,我們會在24小時內與您取得聯(lián)系。