[RESUELTO] Acumular datos en una misma celda
[RESUELTO] Acumular datos en una misma celda
Hola me llamo Julio
Nunca toque OpenOffice y el caso es que necesito correr una hoja de calculo con macros en el SPAM. La macros la tengo hecha en VBA y no tengo ni idea de como hacerla en Open Office.
La macros solo tiene que a cumular datos en la misma celda, Ejemplo:
en la celda "C2" se acumula el dato que ponga en la celda "G2" sumándose y el dato que ponga en la celda "F2" se acumula en "C2" restando.
en la celda "C3" se acumula el dato que ponga en la celda "G3" sumándose y el dato que ponga en la celda "F3" se acumula en "C3" restando, y asi sucesivamente.
Y para finalizar hay otra macros que cuando cierro el libro y lo vuelvo a abrir toda la información que existe en las celdas "F y G" se borran.
Pueden ayudarme?
Un saludo
Nunca toque OpenOffice y el caso es que necesito correr una hoja de calculo con macros en el SPAM. La macros la tengo hecha en VBA y no tengo ni idea de como hacerla en Open Office.
La macros solo tiene que a cumular datos en la misma celda, Ejemplo:
en la celda "C2" se acumula el dato que ponga en la celda "G2" sumándose y el dato que ponga en la celda "F2" se acumula en "C2" restando.
en la celda "C3" se acumula el dato que ponga en la celda "G3" sumándose y el dato que ponga en la celda "F3" se acumula en "C3" restando, y asi sucesivamente.
Y para finalizar hay otra macros que cuando cierro el libro y lo vuelvo a abrir toda la información que existe en las celdas "F y G" se borran.
Pueden ayudarme?
Un saludo
Última edición por juliocha el Mié Abr 04, 2018 8:13 pm, editado 2 veces en total.
OpenOffice 4.1.5
Windows 7 Profesional 64
Windows 7 Profesional 64
Re: Acumular datos en una misma celda
hay algo de duda en tu consulta, por ejemplo en Calc no existen las celdas F y G, tal vez te refieras a las celdas G2, G3, F2, F3 .... no sé.juliocha escribió:Y para finalizar hay otra macros que cuando cierro el libro y lo vuelvo a abrir toda la información que existe en las celdas "F y G" se borran.
Envía por favor un archivo ejemplo con la macro VBA que utilizas.
Saludos.
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Re: Acumular datos en una misma celda
Perdon, efectivamente es "F2" y"G2"
Y la macros del borrado de las celdas es:
Un Saludo
Código: Seleccionar todo
Private Sub Worksheet_Change(ByVal Target As Range): On Error Resume Next
If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then 'Una celda
If Target.Row > 1 Then 'Después de la fila 1
Application.EnableEvents = False
Select Case Target.Column
Case 6: Range("C" & Target.Row) = Range("C" & Target.Row) - Target 'Columna F
Case 7: Range("C" & Target.Row) = Range("C" & Target.Row) + Target 'Columna G
End Select
Application.EnableEvents = True
End If
End If
End Sub
Código: Seleccionar todo
Private Sub Workbook_Open()
Sheets("EXISTENCIAS").Range("F2:F100,G2:G100").ClearContents
End Sub
OpenOffice 4.1.5
Windows 7 Profesional 64
Windows 7 Profesional 64
Re: Acumular datos en una misma celda
Debería ser así tal vez en OpenOffice Basic:
Código: Seleccionar todo
Sub acumular(Target)
If Target.ImplementationName <> "ScCellObj" Then Exit Sub
fila = Target.CellAddress.Row
If fila = 0 Then Exit Sub
columna = Target.CellAddress.Column
hoja = ThisComponent.CurrentController.ActiveSheet
celda = hoja.getCellByPosition(columna, fila)
If columna = 5 Then
oCol = hoja.getCellByPosition(columna - 3, fila)
oCol.Value = oCol.Value - celda.Value
ElseIf columna = 6 Then
oCol = hoja.getCellByPosition(columna - 4, fila)
oCol.Value = oCol.Value + celda.Value
End If
End Sub
Código: Seleccionar todo
Sub Borrar()
oSheets = ThisComponent.Sheets
oSheets.getByName("EXISTENCIAS").getCellRangeByName("F2:F100").ClearContents(1023)
oSheets.getByName("EXISTENCIAS").getCellRangeByName("G2:G100").ClearContents(1023)
End Sub
- Adjuntos
-
- eventoAlCambiar.ods
- Acumular
- (9.48 KiB) Descargado 182 veces
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Re: Acumular datos en una misma celda
Gracias por contestar fornelasa y por tu interés por ayudarme.
No te conteste antes por que no pude probarlo por falta de tiempo. Hace un rato lo pude probar en la hoja definitiva y funciona perfectamente, ahora tengo que intentar aprender y entender un poco sobre este lenguaje ya que no me gusta hacer solo un copy/pega y ya esta.
Muchas Gracias
No te conteste antes por que no pude probarlo por falta de tiempo. Hace un rato lo pude probar en la hoja definitiva y funciona perfectamente, ahora tengo que intentar aprender y entender un poco sobre este lenguaje ya que no me gusta hacer solo un copy/pega y ya esta.
Muchas Gracias
OpenOffice 4.1.5
Windows 7 Profesional 64
Windows 7 Profesional 64
Re: [RESUELTO] Acumular datos en una misma celda
ok bien, que bueno que ya quedó.
Si te interesa Python:
Si te interesa Python:
Código: Seleccionar todo
def acumular(Target):
if Target.getImplementationName() != 'ScCellObj':
return
fila = Target.getCellAddress().Row
if fila == 0:
return
columna = Target.getCellAddress().Column
doc = XSCRIPTCONTEXT.getDocument()
hoja = doc.getCurrentController().getActiveSheet()
celda = hoja.getCellByPosition(columna, fila)
if columna == 5:
oCol = hoja.getCellByPosition(columna - 3, fila)
oCol.Value = oCol.getValue() - celda.getValue()
if columna == 6:
oCol = hoja.getCellByPosition(columna - 4, fila)
oCol.Value = oCol.getValue() + celda.getValue()
return
Código: Seleccionar todo
def borrar(event):
doc = XSCRIPTCONTEXT.getDocument()
oSheets = doc.getSheets()
oSheets.getByName('Existencias').getCellRangeByName('F2:F100').clearContents(1023)
oSheets.getByName('Existencias').getCellRangeByName('G2:G100').clearContents(1023)
return
- Adjuntos
-
- Acumulador.ods
- En python
- (9.86 KiB) Descargado 186 veces
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Re: [RESUELTO] Acumular datos en una misma celda
O tal vez en JavaScript ....
Saludos, Federico.
Código: Seleccionar todo
importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.frame.XModel);
importClass(Packages.com.sun.star.lang.XServiceInfo);
importClass(Packages.com.sun.star.sheet.XCellAddressable);
importClass(Packages.com.sun.star.sheet.XSpreadsheetView);
importClass(Packages.com.sun.star.table.XCellRange);
importClass(Packages.com.sun.star.table.XCell);
doc = XSCRIPTCONTEXT.getDocument();
curr = UnoRuntime.queryInterface(XModel, doc);
celda = curr.getCurrentSelection();
imple = UnoRuntime.queryInterface(XServiceInfo, celda);
rng = imple.getImplementationName();
if(rng=="ScCellObj")
{
ocelda = UnoRuntime.queryInterface(XCellAddressable, celda);
fila = ocelda.getCellAddress().Row
if(fila>0)
{
columna = ocelda.getCellAddress().Column
docto = UnoRuntime.queryInterface(XModel, doc);
tccc = docto.getCurrentController();
otccc = UnoRuntime.queryInterface(XSpreadsheetView, tccc);
hoja = otccc.getActiveSheet();
ohoja = UnoRuntime.queryInterface(XCellRange, hoja);
celda = ohoja.getCellByPosition(columna, fila);
valorI = UnoRuntime.queryInterface(XCell, celda);
dato = valorI.getValue();
if(columna==5)
{
izda = ohoja.getCellByPosition(columna - 3, fila);
valorJ = UnoRuntime.queryInterface(XCell, izda);
datoJ = valorJ.getValue();
izda.setValue(datoJ - dato);
}
if(columna==6)
{
izda = ohoja.getCellByPosition(columna - 4, fila);
valorJ = UnoRuntime.queryInterface(XCell, izda);
datoJ = valorJ.getValue();
izda.setValue(datoJ + dato);
}
}
}
Código: Seleccionar todo
importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.sheet.XSpreadsheetDocument);
importClass(Packages.com.sun.star.container.XNameAccess);
importClass(Packages.com.sun.star.table.XCellRange);
importClass(Packages.com.sun.star.sheet.XSheetOperation);
doc = XSCRIPTCONTEXT.getDocument();
hojas = UnoRuntime.queryInterface(XSpreadsheetDocument, doc);
ohojas = hojas.getSheets();
nombre = UnoRuntime.queryInterface(XNameAccess, ohojas);
onombre = nombre.getByName("Existencias");
getnoms = UnoRuntime.queryInterface(XCellRange, onombre);
ogetnoms = getnoms.getCellRangeByName("F2:F10");
pgetnoms = getnoms.getCellRangeByName("G2:G10");
borrado = UnoRuntime.queryInterface(XSheetOperation, ogetnoms);
bborrado = UnoRuntime.queryInterface(XSheetOperation, pgetnoms);
oborrado = borrado.clearContents(1023);
pborrado = bborrado.clearContents(1023);
- Adjuntos
-
- AlCambiarElDatoB.ods
- En JavaScript
- (11.11 KiB) Descargado 179 veces
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Re: [RESUELTO] Acumular datos en una misma celda
En resumen:
La macro VBA presentada por juliocha fue "traducida" en lenguaje:
OpenOffice Basic
Python
JavaScript
y ahora en BeanShell.
Tal vez las macros presentadas no sean una oda a las buenas practicas de programación pero funcionan para lo que el usuario inicial comentó, sirvan pues como ejemplo de los diferentes lenguajes que maneja OpenOffice / LibreOffice.
Saludos, Federico.
La macro VBA presentada por juliocha fue "traducida" en lenguaje:
OpenOffice Basic
Python
JavaScript
y ahora en BeanShell.
Código: Seleccionar todo
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.sheet.XCellAddressable;
import com.sun.star.sheet.XSpreadsheetView;
import com.sun.star.table.XCellRange;
import com.sun.star.table.XCell;
doc = XSCRIPTCONTEXT.getDocument();
curr = UnoRuntime.queryInterface(XModel.class, doc);
celda = curr.getCurrentSelection();
imple = UnoRuntime.queryInterface(XServiceInfo.class, celda);
rng = imple.getImplementationName();
String texto = "ScCellObj";
if ( texto.equals(rng) )
{
ocelda = UnoRuntime.queryInterface(XCellAddressable.class, celda);
int fila = ocelda.getCellAddress().Row;
if(fila>0)
{
columna = ocelda.getCellAddress().Column;
docto = UnoRuntime.queryInterface(XModel.class, doc);
tccc = docto.getCurrentController();
otccc = UnoRuntime.queryInterface(XSpreadsheetView.class, tccc);
hoja = otccc.getActiveSheet();
ohoja = UnoRuntime.queryInterface(XCellRange.class, hoja);
celda = ohoja.getCellByPosition(columna, fila);
valorI = UnoRuntime.queryInterface(XCell.class, celda);
int dato = valorI.getValue();
if(columna==5)
{
izda = ohoja.getCellByPosition(columna - 3, fila);
valorJ = UnoRuntime.queryInterface(XCell.class, izda);
int datoJ = valorJ.getValue();
izda.setValue(datoJ - dato);
}
if(columna==6)
{
izda = ohoja.getCellByPosition(columna - 4, fila);
valorJ = UnoRuntime.queryInterface(XCell.class, izda);
int datoJ = valorJ.getValue();
izda.setValue(datoJ + dato);
}
}
}
Código: Seleccionar todo
import com.sun.star.uno.UnoRuntime;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.container.XNameAccess;
import com.sun.star.table.XCellRange;
import com.sun.star.sheet.XSheetOperation;
doc = XSCRIPTCONTEXT.getDocument();
hojas = UnoRuntime.queryInterface(XSpreadsheetDocument.class, doc);
ohojas = hojas.getSheets();
nombre = UnoRuntime.queryInterface(XNameAccess.class, ohojas);
onombre = nombre.getByName("Existencias");
getnoms = UnoRuntime.queryInterface(XCellRange.class, onombre);
ogetnoms = getnoms.getCellRangeByName("F2:F10");
pgetnoms = getnoms.getCellRangeByName("G2:G10");
oborrado = UnoRuntime.queryInterface(XSheetOperation.class, ogetnoms);
bborrado = UnoRuntime.queryInterface(XSheetOperation.class, pgetnoms);
oborrado.clearContents(1023);
bborrado.clearContents(1023);
Saludos, Federico.
- Adjuntos
-
- ConBeanShell.ods
- Con BeanShell
- (11.71 KiB) Descargado 179 veces
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Re: [RESUELTO] Acumular datos en una misma celda
OK, ya veo las posibilidades del open office, pero para empezar continuare con basic poco a poco
OpenOffice 4.1.5
Windows 7 Profesional 64
Windows 7 Profesional 64