My code is here,can you check it for me? thanks ! public void InitiFile(Excel excel,string tempfile,string stempid) { Worksheet sheet=getTemplateSheet(tempfile,stempid); Cells cells = sheet.Cells; string fName=sheet.Name; int index=excel.Worksheets.Add(); excel.Worksheets[index].Copy(sheet); Worksheets sheets=excel.Worksheets; sheets[0].Name=fName+"(1)"; this.FillSheet(sheets[0],opid); //excel.Save(resultfile,FileFormatType.Default);
} public Worksheet getTemplateSheet(string tempfilename,string stempid) { Excel excel=new Excel(); excel.Open(tempfilename); Worksheet sheet=null; switch (stempid) { case "9": sheet=excel.Worksheets["Upper HF Welding Process"]; break; case "2": sheet=excel.Worksheets["Skiving Instruction"]; break; case "10": goto case "9"; } DeleteTempletSheet(excel.Worksheets,sheet.Name); return excel.Worksheets[0]; }
public void DeleteTempletSheet(Worksheets sheets,string sheetName) { int index=sheets.Count; while(index > 0) { Worksheet sheet=sheets[index-1]; if (sheet.Name!=sheetName.ToString()) { sheets.RemoveAt(index-1); } index--; }
Thanks for your reply quickly! I do it as you saying,but throw exception 'The same worksheet name already exists'. Where is the wrong? Can you help me? Thanks!
Thanks for your reply,I use the new fix, i test the code of you provide,it's ok,but when i changed the line 'return excel.worksheets[0]' to 'return sheet' ,it can gets the file 'abc.xls' .but when i open the file throw exception,so i can't open the file .
thanks for your reply,The following is my test code ,throw exception 'The same worksheet name already exists' yet. if the reason is :the aspose excel i used is evaluation? if i use the formal copyright will to solve the problem?
public static void InitiFile(Excel excel,string tempfile,string stempid,ref int icount) { if (File.Exists("d:\\test\\abc.xls")) excel.Open("d:\\test\\abc.xls"); Worksheet sheet=getTemplateSheet(tempfile,stempid); string fName=sheet.Name; int index=excel.Worksheets.Add(); excel.Worksheets[index].Copy(sheet); excel.Worksheets[index].Name=fName+"("+icount.ToString()+")"; Cells cells=excel.Worksheets[index].Cells; cells.ClearContents(6,0,cells.Rows.Count-1,9); cells[4,3].PutValue("abc"); excel.Save("d:\\test\\abc.xls"); icount++;
}
static void InitFile() { int icount=1; Excel excel=new Excel();
Has this been fixed? I can duplicate the problem easily. I am using the latest posted version. The spreadsheet I am starting with, template.xls, is empty and I have removed all substituion code for clarity.