Problem on the release of resource C # :
The prog must convert a file calc in a file Excel 2007 (ods -> xls).
At the end of the file xls, it remains locked for a period of 10 seconds.
What will not meet my needs .. I need my speed over available
Ex (code, reflexion and object) :
public void ConvertToExcel()
{
// textBox1.Text : name of file.ods
if(textBox1.Text == null || textBox1.Text.Equals(string.Empty) || (!System.IO.File.Exists(textBox1.Text)))
return;
string fileName = textBox1.Text;
//Create a new ServiceManager Type object
Type tServiceManager = Type.GetTypeFromProgID("com.sun.star.ServiceManager",true);
//Create a new ServiceManager Com object using our
//ServiceManager type object
object oServiceManager = System.Activator.CreateInstance(tServiceManager);
//Create our Desktop Com object
object[] args1 = new object[] {"com.sun.star.frame.Desktop" };
object oDesktop = oServiceManager.GetType().InvokeMember("createinstance",
BindingFlags.InvokeMethod, null,
oServiceManager, args1) as object;
XComponent oComponent = getXComponent(fileName);
// Output :
string fileExcelName = @"C:\test.xls";
unoidl.com.sun.star.beans.PropertyValue[] outProps = new unoidl.com.sun.star.beans.PropertyValue[3];
outProps[0] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[0].Name = "FilterName";
outProps[0].Value = new uno.Any("MS Excel 97");
outProps[1] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[1].Name = "Overwrite";
outProps[1].Value = new uno.Any(true);
outProps[2] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[2].Name = "OutputStream";
outProps[2].Value = new uno.Any(
typeof(unoidl.com.sun.star.io.XOutputStream),
new XOutputStreamWrapper(System.IO.File.Create(fileExcelName)));
((unoidl.com.sun.star.frame.XStorable)oComponent).storeToURL("private:stream", outProps);
oComponent.dispose();
oComponent = null;
//oDesktop.terminate();
GC.Collect();
GC.WaitForPendingFinalizers();
}// End Methode
(...)
private XComponent getXComponent(string inputFile)
{
XComponentContext localContext = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();
XComponentLoader componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
PropertyValue[] propertyValue = new PropertyValue[1];
PropertyValue aProperty = new PropertyValue();
aProperty.Name = "Hidden";
aProperty.Value = new uno.Any(true);
propertyValue[0] = aProperty;
string pathFile = PathConverter(inputFile);
XComponent xComponent = componentLoader.loadComponentFromURL(pathFile, "_blank", 0, propertyValue);
return xComponent;
}
Please, who can help me ?
thank you in advance
[Uno, C#] Problem on the release of resource
[Uno, C#] Problem on the release of resource
OOo 2.3.X on Ms Windows XP + ms server 2003
Re: [Uno, C#] Problem on the release of resource
OOo does not save the Excel 2007 crap (OOXML, *.xlsx). You may try the Novel suite instead.
http://www.oooninja.com/2008/02/batch-c ... -with.html is a script which is well known to convert "anything-to-anything" in kind of "server mode".
Edit: I see, you mean binary xls. |
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Uno, C#] Problem on the release of resource
Solution :
(OUPS, file open and not closed)
unoidl.com.sun.star.beans.PropertyValue[] outProps = new unoidl.com.sun.star.beans.PropertyValue[3];
outProps[0] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[0].Name = "FilterName";
outProps[0].Value = new uno.Any("MS Excel 97");
outProps[1] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[1].Name = "Overwrite";
outProps[1].Value = new uno.Any(true);
outProps[2] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[2].Name = "OutputStream";
using (System.IO.FileStream newFileExcel = System.IO.File.Create(fileExcelName))
{
XOutputStreamWrapper outputWapperFile = new XOutputStreamWrapper(newFileExcel);
outProps[2].Value = new uno.Any(
typeof(unoidl.com.sun.star.io.XOutputStream), outputWapperFile);
((unoidl.com.sun.star.frame.XStorable)oComponent).storeToURL("private:stream", outProps);
oComponent.dispose();
oComponent = null;
//oDesktop.terminate();
outputWapperFile.closeOutput();
newFileExcel.Close(); // This is my nervous ticks , it's not.. with le class of framwork.....
}
GC.Collect();
GC.WaitForPendingFinalizers();
(OUPS, file open and not closed)
unoidl.com.sun.star.beans.PropertyValue[] outProps = new unoidl.com.sun.star.beans.PropertyValue[3];
outProps[0] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[0].Name = "FilterName";
outProps[0].Value = new uno.Any("MS Excel 97");
outProps[1] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[1].Name = "Overwrite";
outProps[1].Value = new uno.Any(true);
outProps[2] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[2].Name = "OutputStream";
using (System.IO.FileStream newFileExcel = System.IO.File.Create(fileExcelName))
{
XOutputStreamWrapper outputWapperFile = new XOutputStreamWrapper(newFileExcel);
outProps[2].Value = new uno.Any(
typeof(unoidl.com.sun.star.io.XOutputStream), outputWapperFile);
((unoidl.com.sun.star.frame.XStorable)oComponent).storeToURL("private:stream", outProps);
oComponent.dispose();
oComponent = null;
//oDesktop.terminate();
outputWapperFile.closeOutput();
newFileExcel.Close(); // This is my nervous ticks , it's not.. with le class of framwork.....
}
GC.Collect();
GC.WaitForPendingFinalizers();
OOo 2.3.X on Ms Windows XP + ms server 2003
Re: [Uno, C#] Problem on the release of resource
Thank you for your help!
Excel ... I made sharepoint
Good day .
Excel ... I made sharepoint
Good day .
OOo 2.3.X on Ms Windows XP + ms server 2003
Re: [Uno, C#] Problem on the release of resource
public void ConvertToExcel(string inputFile, string outputFile)
{
string fileName = string.Empty;
if (inputFile == null || inputFile.Equals(string.Empty) || (!System.IO.File.Exists(inputFile)))
{
// Log,
// throw new Excep.....
return;
}
fileName = inputFile;
#region Open file calc
XComponent oComponent = null;
oComponent = getXComponent(fileName);
#endregion Open file calc
#region Save Excel
string fileExcelName = outputFile;
unoidl.com.sun.star.beans.PropertyValue[] outProps = new unoidl.com.sun.star.beans.PropertyValue[3];
outProps[0] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[0].Name = "FilterName";
outProps[0].Value = new uno.Any("MS Excel 97");
outProps[1] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[1].Name = "Overwrite";
outProps[1].Value = new uno.Any(true);
outProps[2] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[2].Name = "OutputStream";
using (System.IO.FileStream newFileExcel = System.IO.File.Create(fileExcelName))
{
XOutputStreamWrapper outputWapperFile = new XOutputStreamWrapper(newFileExcel);
outProps[2].Value = new uno.Any(
typeof(unoidl.com.sun.star.io.XOutputStream), outputWapperFile);
((unoidl.com.sun.star.frame.XStorable)oComponent).storeToURL("private:stream", outProps);
oComponent.dispose();
oComponent = null;
//oDesktop.terminate();
outputWapperFile.closeOutput();
newFileExcel.Close();
}
GC.Collect();
GC.WaitForPendingFinalizers();
#endregion Save Excel
}
/// <summary>
///
/// </summary>
/// <param name="inputFile"></param>
/// <returns></returns>
private XComponent getXComponent(string inputFile)
{
XComponentContext localContext = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();
XComponentLoader componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
PropertyValue[] propertyValue = new PropertyValue[1];
PropertyValue aProperty = new PropertyValue();
aProperty.Name = "Hidden";
aProperty.Value = new uno.Any(true);
propertyValue[0] = aProperty;
string pathFile = PathConverter(inputFile);
XComponent xComponent = componentLoader.loadComponentFromURL(pathFile, "_blank", 0, propertyValue);
return xComponent;
}
/// <summary>
///
/// "File///C:/pathFilmeName"
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
private static string PathConverter(string file)
{
try
{
file = file.Replace(@"\", "/");
return "file:///" + file;
}
catch (System.Exception ex)
{
throw ex;
}
}
{
string fileName = string.Empty;
if (inputFile == null || inputFile.Equals(string.Empty) || (!System.IO.File.Exists(inputFile)))
{
// Log,
// throw new Excep.....
return;
}
fileName = inputFile;
#region Open file calc
XComponent oComponent = null;
oComponent = getXComponent(fileName);
#endregion Open file calc
#region Save Excel
string fileExcelName = outputFile;
unoidl.com.sun.star.beans.PropertyValue[] outProps = new unoidl.com.sun.star.beans.PropertyValue[3];
outProps[0] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[0].Name = "FilterName";
outProps[0].Value = new uno.Any("MS Excel 97");
outProps[1] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[1].Name = "Overwrite";
outProps[1].Value = new uno.Any(true);
outProps[2] = new unoidl.com.sun.star.beans.PropertyValue();
outProps[2].Name = "OutputStream";
using (System.IO.FileStream newFileExcel = System.IO.File.Create(fileExcelName))
{
XOutputStreamWrapper outputWapperFile = new XOutputStreamWrapper(newFileExcel);
outProps[2].Value = new uno.Any(
typeof(unoidl.com.sun.star.io.XOutputStream), outputWapperFile);
((unoidl.com.sun.star.frame.XStorable)oComponent).storeToURL("private:stream", outProps);
oComponent.dispose();
oComponent = null;
//oDesktop.terminate();
outputWapperFile.closeOutput();
newFileExcel.Close();
}
GC.Collect();
GC.WaitForPendingFinalizers();
#endregion Save Excel
}
/// <summary>
///
/// </summary>
/// <param name="inputFile"></param>
/// <returns></returns>
private XComponent getXComponent(string inputFile)
{
XComponentContext localContext = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();
XComponentLoader componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
PropertyValue[] propertyValue = new PropertyValue[1];
PropertyValue aProperty = new PropertyValue();
aProperty.Name = "Hidden";
aProperty.Value = new uno.Any(true);
propertyValue[0] = aProperty;
string pathFile = PathConverter(inputFile);
XComponent xComponent = componentLoader.loadComponentFromURL(pathFile, "_blank", 0, propertyValue);
return xComponent;
}
/// <summary>
///
/// "File///C:/pathFilmeName"
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
private static string PathConverter(string file)
{
try
{
file = file.Replace(@"\", "/");
return "file:///" + file;
}
catch (System.Exception ex)
{
throw ex;
}
}
OOo 2.3.X on Ms Windows XP + ms server 2003