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);
相关阅读 更多 +