aditya_050484


var xlApp, xlWB, xlSheet,f2,fso,oBook,oSheet,oBook1,oSheet1,idTmr;

xlApp = new ActiveXObject("Excel.Application");
fso = new ActiveXObject("Scripting.FileSystemObject");

if(fso.FileExists("c:\\Example.XLS"))
{
f2=fso.GetFile("c:\\Example.XLS");
f2.Delete();
}
xlApp.Visible = true;
xlApp.DisplayAlerts=false
xlWB = xlApp.Workbooks.Add();
xlWB.Sheets.Add(null,xlWB.Sheets(xlWB.Sheets.Count));
xlWB.WorkSheets(1).Name="Redmond_Enabled";
xlWB.WorkSheets(2).Name="Redmond_Disabled";
xlWB.WorkSheets(3).Name="PHX_Enabled";
xlWB.WorkSheets(4).Name="PHX_Disabled";

xlSheet = xlWB.WorkSheets(1);
xlSheet.Activate();

xlSheet.Cells(1,1).Value = "job name";
xlSheet.Cells(1,2).Value = "job ID";

xlSheet.Cells(2,1).Value = "a";
xlSheet.Cells(2,2).Value = "a1";

xlSheet.Cells(3,1).Value = "b";
xlSheet.Cells(3,2).Value = "b1";

xlSheet.Cells(4,1).Value = "c";
xlSheet.Cells(4,2).Value = "c1";

xlSheet = xlWB.WorkSheets(2);

xlSheet.Activate();
xlSheet.Cells(1,1).Value = "job name";
xlSheet.Cells(1,2).Value = "job ID";

xlSheet.Cells(2,1).Value = "a";
xlSheet.Cells(2,2).Value = "a1";

xlSheet.Cells(3,1).Value = "b";
xlSheet.Cells(3,2).Value = "b1";

xlSheet.Cells(4,1).Value = "c";
xlSheet.Cells(4,2).Value = "c1";


var oExcelApp = new ActiveXObject("Excel.Application");
var oWkBks = oExcelApp.Workbooks;
oWkBks.open("c:\\Example_PHX.xlsx");

oBook = oWkBks.Item(1);
oSheet = oBook.Worksheets.Item(1);


oSheet.Activate();
oSheet.Cells.Select();

oExcelApp.Selection.Copy();

xlSheet = xlWB.WorkSheets(3);
xlSheet.Activate();
xlSheet.Paste();

oBook = oWkBks.Item(2);
oSheet = oBook.Worksheets.Item(2);


oSheet.Activate();
oSheet.Cells.Select();

oExcelApp.Selection.Copy();

xlSheet = xlWB.WorkSheets(4);
xlSheet.Activate();
xlSheet.Paste();

xlSheet.SaveAS("C:\\Example.XLSx");
xlApp.Quit();
xlApp = null;
CollectGarbage(1500);

After copying 1st worksheet to the 3rd worksheet,it throws Exception..Please suggest where I

am doing wrong...Is there any problmem of garbage collector

Please reply me to adityamandlekar@yahoo.com or v-admand@microsoft.com if possible..its

urgent!!!





Re: How to Copy 2 worksheet from one excel sheet to to 2 Worksheet of another Excel Sheet

Tamar E. Granor


What language are you writing this in. Your code looks like some VB variant, but you're asking in a Visual FoxPro group.

Tamar





Re: How to Copy 2 worksheet from one excel sheet to to 2 Worksheet of another Excel Sheet

CetinBasoz

It would be:

xlApp.ActiveWorkbook.WorkSheets( < nSource > ).Copy( < oDestination > );

However I didn'tunderstand what does "2 worksheet from one excel sheet to 2 worksheet of another Excel sheet" mean. Anyway you could do something like:

var oSource = xlApp.ActiveWorkBook.WorkSheets(1).UsedRange;
var oTarget = xlApp.ActiveWorkBook.WorkSheets(2).Range("A1");
oSource.Copy(oTarget);

Copy syntax also supports copying between workbooks. Then you could index workbooks with their filenames.






Re: How to Copy 2 worksheet from one excel sheet to to 2 Worksheet of another Excel Sheet

CetinBasoz

Hi Tamar,

She/he is using jscript.