c#实现根据服务器上已存在的文档模板创建文件
时间:2007-03-07 来源:twanger
根据服务器已存在的模板信息,填写相关内容形成新的文档。
代码如下:
public bool writeFile(FileMsg fileMsg,String templateFileName,String fileSaveFolder, String fileOldName ,String fileNewName,String fileType,bool createFile)
{
bool rtnFlg = true; putlog("writeFile:1"); // テンプレート経路
string strTempFileName = templateFilePath + "\\" + templateFileName + @".xls"; // 原文書名 string strSourceFileName = fileSaveFolder + "\\" + fileOldName + @".xls"; string tmpSourceFileName = "";
// 新規文書名 string strSaveFileName = fileSaveFolder + "\\" + fileNewName + @".xls"; Excel.Application ThisApplication = new Excel.ApplicationClass();
Excel.Workbook ThisWorkBook; try
{
putlog("writeFile:2"); // 経路を存在しない
if (!Directory.Exists(fileSaveFolder))
{
putlog("writeFile:2-1"); // 経路を新規
Directory.CreateDirectory(fileSaveFolder);
}
object missing = System.Reflection.Missing.Value; putlog("writeFile:3"); if (createFile)
{
putlog("writeFile:3-1"); // テンプレート文書を開ける
ThisWorkBook = ThisApplication.Workbooks.Open(strTempFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
{
bool rtnFlg = true; putlog("writeFile:1"); // テンプレート経路
string strTempFileName = templateFilePath + "\\" + templateFileName + @".xls"; // 原文書名 string strSourceFileName = fileSaveFolder + "\\" + fileOldName + @".xls"; string tmpSourceFileName = "";
// 新規文書名 string strSaveFileName = fileSaveFolder + "\\" + fileNewName + @".xls"; Excel.Application ThisApplication = new Excel.ApplicationClass();
Excel.Workbook ThisWorkBook; try
{
putlog("writeFile:2"); // 経路を存在しない
if (!Directory.Exists(fileSaveFolder))
{
putlog("writeFile:2-1"); // 経路を新規
Directory.CreateDirectory(fileSaveFolder);
}
object missing = System.Reflection.Missing.Value; putlog("writeFile:3"); if (createFile)
{
putlog("writeFile:3-1"); // テンプレート文書を開ける
ThisWorkBook = ThisApplication.Workbooks.Open(strTempFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
相关阅读 更多 +
排行榜 更多 +

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />
飞行射击 下载- 4 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载73.78MB · 95℃
1970-01-01
- 5 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载43.7 MB · 96℃
1970-01-01
- 6 <img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />下载110.69MB · 94℃
1970-01-01