Alaska Software Inc. - Excel book is already opened
Username: Password:
AuthorTopic: Excel book is already opened
Domingo SerranoExcel book is already opened
on Mon, 13 Jul 2015 18:16:59 +0200
Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName) 

Thanks in advance,
CESAR CALVORe: Excel book is already opened
on Mon, 13 Jul 2015 22:36:43 +0200
Hello Domingo, here you are one example but if you has ODBCDBE or SqlExpress 
would be better for work with a lot of datas.
This example is for create the head of one sheet and color or alignment.
Regards.
César.

oExcel := CreateObject( "EXCEL.APPLICATION" )

oBook := oExcel:workbooks:open(cFIL)

oExcel:Visible := .F.

oSheet := oExcel:Worksheets( "Hoja1" )

oSheet:Columns("A:A"):ColumnWidth = 05
oSheet:Columns("A:A"):HorizontalAlignment = xlCenter
oSheet:Columns("A:A"):Interior:Color = rgbWhite

oSheet:Columns("B:B"):ColumnWidth = 05
oSheet:Columns("B:B"):HorizontalAlignment = xlCenter
oSheet:Columns("B:B"):Interior:Color = rgbWhite

oSheet:Columns("C:C"):ColumnWidth = 10
oSheet:Columns("C:C"):HorizontalAlignment = xlCenter
oSheet:Columns("C:C"):Interior:Color = rgbWhite

oSheet:Columns("D:D"):ColumnWidth = 20
oSheet:Columns("D:D"):HorizontalAlignment = xlCenter
oSheet:Columns("D:D"):Interior:Color = rgbWhite

oSheet:Columns("E:E"):ColumnWidth = 04
oSheet:Columns("E:E"):HorizontalAlignment = xlCenter
oSheet:Columns("E:E"):Interior:Color = rgbWhite

oSheet:Columns("F:F"):ColumnWidth = 04
oSheet:Columns("F:F"):HorizontalAlignment = xlCenter
oSheet:Columns("F:F"):Interior:Color = rgbWhite

oSheet:Columns("G:G"):ColumnWidth = 10
oSheet:Columns("G:G"):HorizontalAlignment = xlCenter
oSheet:Columns("G:G"):Interior:Color = rgbWhite

oSheet:Columns("H:H"):ColumnWidth = 10
oSheet:Columns("H:H"):HorizontalAlignment = xlCenter
oSheet:Columns("H:H"):Interior:Color = rgbWhite

oSheet:Columns("I:I"):ColumnWidth = 60
oSheet:Columns("I:I"):HorizontalAlignment = xlCenter
oSheet:Columns("I:I"):Interior:Color = rgbWhite

oSheet:Columns("J:J"):ColumnWidth = 10
oSheet:Columns("J:J"):HorizontalAlignment = xlCenter
oSheet:Columns("J:J"):Interior:Color = rgbWhite

oSheet:Columns("K:K"):ColumnWidth = 10
oSheet:Columns("K:K"):HorizontalAlignment = xlCenter
oSheet:Columns("K:K"):Interior:Color = rgbWhite

oSheet:Columns("L:L"):ColumnWidth = 10
oSheet:Columns("L:L"):HorizontalAlignment = xlCenter
oSheet:Columns("L:L"):Interior:Color = rgbWhite

oSheet:Columns("M:M"):ColumnWidth = 10
oSheet:Columns("M:M"):HorizontalAlignment = xlCenter
oSheet:Columns("M:M"):Interior:Color = rgbWhite

oSheet:Columns("N:N"):ColumnWidth = 15
oSheet:Columns("N:N"):HorizontalAlignment = xlRight
oSheet:Columns("N:N"):Interior:Color = rgbWhite

oSheet:Columns("O:O"):ColumnWidth = 04
oSheet:Columns("O:O"):HorizontalAlignment = xlCenter
oSheet:Columns("O:O"):Interior:Color = rgbWhite

oSheet:Columns("P:P"):ColumnWidth = 15
oSheet:Columns("P:P"):HorizontalAlignment = xlRight
oSheet:Columns("P:P"):Interior:Color = rgbWhite

oSheet:Columns("Q:Q"):ColumnWidth = 04
oSheet:Columns("Q:Q"):HorizontalAlignment = xlCenter
oSheet:Columns("Q:Q"):Interior:Color = rgbWhite

oSheet:Cells(1,01):Value := "SOC"
oSheet:Cells(1,01):Interior:Color = rgbGray
oSheet:Cells(1,01):HorizontalAlignment = xlCenter
oSheet:Cells(1,01):Borders:LineStyle = xlContinuous

oSheet:Cells(1,02):Value := "SGL"
oSheet:Cells(1,02):Interior:Color = rgbGray
oSheet:Cells(1,02):HorizontalAlignment = xlCenter
oSheet:Cells(1,02):Borders:LineStyle = xlContinuous

oSheet:Cells(1,03):Value := "CUE"
oSheet:Cells(1,03):Interior:Color = rgbGray
oSheet:Cells(1,03):HorizontalAlignment = xlCenter
oSheet:Cells(1,03):Borders:LineStyle = xlContinuous

oSheet:Cells(1,04):Value := "ASG"
oSheet:Cells(1,04):Interior:Color = rgbGray
oSheet:Cells(1,04):HorizontalAlignment = xlCenter
oSheet:Cells(1,04):Borders:LineStyle = xlContinuous

oSheet:Cells(1,05):Value := "CLA"
oSheet:Cells(1,05):Interior:Color = rgbGray
oSheet:Cells(1,05):HorizontalAlignment = xlCenter
oSheet:Cells(1,05):Borders:LineStyle = xlContinuous

oSheet:Cells(1,06):Value := "CTC"
oSheet:Cells(1,06):Interior:Color = rgbGray
oSheet:Cells(1,06):HorizontalAlignment = xlCenter
oSheet:Cells(1,06):Borders:LineStyle = xlContinuous

oSheet:Cells(1,07):Value := "DOC"
oSheet:Cells(1,07):Interior:Color = rgbGray
oSheet:Cells(1,07):HorizontalAlignment = xlCenter
oSheet:Cells(1,07):Borders:LineStyle = xlContinuous

oSheet:Cells(1,08):Value := "DCP"
oSheet:Cells(1,08):Interior:Color = rgbGray
oSheet:Cells(1,08):HorizontalAlignment = xlCenter
oSheet:Cells(1,08):Borders:LineStyle = xlContinuous

oSheet:Cells(1,09):Value := "TXT"
oSheet:Cells(1,09):Interior:Color = rgbGray
oSheet:Cells(1,09):HorizontalAlignment = xlCenter
oSheet:Cells(1,09):Borders:LineStyle = xlContinuous

oSheet:Cells(1,10):Value := "CON"
oSheet:Cells(1,10):Interior:Color = rgbGray
oSheet:Cells(1,10):HorizontalAlignment = xlCenter
oSheet:Cells(1,10):Borders:LineStyle = xlContinuous

oSheet:Cells(1,11):Value := "FCO"
oSheet:Cells(1,11):Interior:Color = rgbGray
oSheet:Cells(1,11):HorizontalAlignment = xlCenter
oSheet:Cells(1,11):Borders:LineStyle = xlContinuous

oSheet:Cells(1,12):Value := "FDO"
oSheet:Cells(1,12):Interior:Color = rgbGray
oSheet:Cells(1,12):HorizontalAlignment = xlCenter
oSheet:Cells(1,12):Borders:LineStyle = xlContinuous

oSheet:Cells(1,13):Value := "FVA"
oSheet:Cells(1,13):Interior:Color = rgbGray
oSheet:Cells(1,13):HorizontalAlignment = xlCenter
oSheet:Cells(1,13):Borders:LineStyle = xlContinuous

oSheet:Cells(1,14):Value := "IML"
oSheet:Cells(1,14):Interior:Color = rgbGray
oSheet:Cells(1,14):HorizontalAlignment = xlCenter
oSheet:Cells(1,14):Borders:LineStyle = xlContinuous

oSheet:Cells(1,15):Value := "MLO"
oSheet:Cells(1,15):Interior:Color = rgbGray
oSheet:Cells(1,15):HorizontalAlignment = xlCenter
oSheet:Cells(1,15):Borders:LineStyle = xlContinuous

oSheet:Cells(1,16):Value := "IMD"
oSheet:Cells(1,16):Interior:Color = rgbGray
oSheet:Cells(1,16):HorizontalAlignment = xlCenter
oSheet:Cells(1,16):Borders:LineStyle = xlContinuous

oSheet:Cells(1,17):Value := "MDO"
oSheet:Cells(1,17):Interior:Color = rgbGray
oSheet:Cells(1,17):HorizontalAlignment = xlCenter
oSheet:Cells(1,17):Borders:LineStyle = xlContinuous

oBook:save()
oBook:close(.T.)
oExcel:Quit()
oExcel:Destroy()

"Domingo Serrano" escribió en el mensaje de 
noticias:687ebdfc$55413e93$11d482@news.alaska-software.com...

Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName)

Thanks in advance,
CESAR CALVORe: Excel book is already opened
on Mon, 13 Jul 2015 23:01:34 +0200
And for the type of Columns:

oSheet:Columns("K:K"):NumberFormat = "#.##0,00"
oSheet:Columns("C:C"):NumberFormat = "@"
oSheet:Columns("D:D"):NumberFormat = "DD/MM/AAAA"

"Domingo Serrano" escribió en el mensaje de 
noticias:687ebdfc$55413e93$11d482@news.alaska-software.com...

Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName)

Thanks in advance,
Domingo SerranoRe: Excel book is already opened
on Tue, 14 Jul 2015 18:09:05 +0200
Thank you, Cesar.
My question is... I cannot use ..."Open(...)" because the file is already 
opened. I think I can use "GetObject()" or a similar command.
(Mi pregunta era: como ya está abierto, no puedo utilizar Open(). Supongo 
que puedo hacerlo con GetObject() o algo parecido. ¿Es así?).

Regards,

"CESAR CALVO" escribió en el mensaje de 
noticias:796824c3$6dd2148b$137397@news.alaska-software.com...

And for the type of Columns:

oSheet:Columns("K:K"):NumberFormat = "#.##0,00"
oSheet:Columns("C:C"):NumberFormat = "@"
oSheet:Columns("D:D"):NumberFormat = "DD/MM/AAAA"

"Domingo Serrano" escribió en el mensaje de
noticias:687ebdfc$55413e93$11d482@news.alaska-software.com...

Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName)

Thanks in advance,
CESAR CALVORe: Excel book is already opened
on Tue, 14 Jul 2015 22:30:19 +0200
Hello Domingo, now I am going to my home and is late.
Tomorrow I will anwser you.
César.

P.D.: I see you speak Spanish. Where are you came from?


"Domingo Serrano" escribió en el mensaje de 
noticias:71ecb315$1d5571c1$181b7b@news.alaska-software.com...

Thank you, Cesar.
My question is... I cannot use ..."Open(...)" because the file is already
opened. I think I can use "GetObject()" or a similar command.
(Mi pregunta era: como ya está abierto, no puedo utilizar Open(). Supongo
que puedo hacerlo con GetObject() o algo parecido. ¿Es así?).

Regards,

"CESAR CALVO" escribió en el mensaje de
noticias:796824c3$6dd2148b$137397@news.alaska-software.com...

And for the type of Columns:

oSheet:Columns("K:K"):NumberFormat = "#.##0,00"
oSheet:Columns("C:C"):NumberFormat = "@"
oSheet:Columns("D:D"):NumberFormat = "DD/MM/AAAA"

"Domingo Serrano" escribió en el mensaje de
noticias:687ebdfc$55413e93$11d482@news.alaska-software.com...

Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName)

Thanks in advance,
CESAR CALVORe: Excel book is already opened
on Tue, 14 Jul 2015 23:03:25 +0200
Domingo, here you are one example.

#include "Fileio.ch"


 HOJA A TRATAR

cFIL := ::cDir + "DATOS.xlsx"

 COMPRUEBA SI LA HOJA ESTÁ ABIERTA PARA CERRARLA

nHandle := FOpen( cFIL, FO_READWRITE )

IF FError() <> 0

   FClose( nHandle )

   oExcel = GetObject(  cFIL,"Excel.Application" )

   oExcel:ActiveWorkbook:Save()

   oExcel:ActiveWorkbook:Close()

   ELSE

   FClose( nHandle )

ENDIF



"Domingo Serrano" escribió en el mensaje de 
noticias:71ecb315$1d5571c1$181b7b@news.alaska-software.com...

Thank you, Cesar.
My question is... I cannot use ..."Open(...)" because the file is already
opened. I think I can use "GetObject()" or a similar command.
(Mi pregunta era: como ya está abierto, no puedo utilizar Open(). Supongo
que puedo hacerlo con GetObject() o algo parecido. ¿Es así?).

Regards,

"CESAR CALVO" escribió en el mensaje de
noticias:796824c3$6dd2148b$137397@news.alaska-software.com...

And for the type of Columns:

oSheet:Columns("K:K"):NumberFormat = "#.##0,00"
oSheet:Columns("C:C"):NumberFormat = "@"
oSheet:Columns("D:D"):NumberFormat = "DD/MM/AAAA"

"Domingo Serrano" escribió en el mensaje de
noticias:687ebdfc$55413e93$11d482@news.alaska-software.com...

Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName)

Thanks in advance,
Domingo SerranoRe: Excel book is already opened
on Wed, 15 Jul 2015 13:57:44 +0200
Thank you, Cesar. This is just what I needed !!

"CESAR CALVO" escribió en el mensaje de 
noticias:62e5d2c$4894e0f2$1a066e@news.alaska-software.com...

Domingo, here you are one example.

#include "Fileio.ch"


 HOJA A TRATAR

cFIL := ::cDir + "DATOS.xlsx"

 COMPRUEBA SI LA HOJA ESTÁ ABIERTA PARA CERRARLA

nHandle := FOpen( cFIL, FO_READWRITE )

IF FError() <> 0

   FClose( nHandle )

   oExcel = GetObject(  cFIL,"Excel.Application" )

   oExcel:ActiveWorkbook:Save()

   oExcel:ActiveWorkbook:Close()

   ELSE

   FClose( nHandle )

ENDIF



"Domingo Serrano" escribió en el mensaje de
noticias:71ecb315$1d5571c1$181b7b@news.alaska-software.com...

Thank you, Cesar.
My question is... I cannot use ..."Open(...)" because the file is already
opened. I think I can use "GetObject()" or a similar command.
(Mi pregunta era: como ya está abierto, no puedo utilizar Open(). Supongo
que puedo hacerlo con GetObject() o algo parecido. ¿Es así?).

Regards,

"CESAR CALVO" escribió en el mensaje de
noticias:796824c3$6dd2148b$137397@news.alaska-software.com...

And for the type of Columns:

oSheet:Columns("K:K"):NumberFormat = "#.##0,00"
oSheet:Columns("C:C"):NumberFormat = "@"
oSheet:Columns("D:D"):NumberFormat = "DD/MM/AAAA"

"Domingo Serrano" escribió en el mensaje de
noticias:687ebdfc$55413e93$11d482@news.alaska-software.com...

Hi,
How can I use a Excel book if it is already opened?
ie:  oBook  := oExcel:WorkBooks:Open(cFileName)

Thanks in advance,