Python via COM Interop

Hi,
in a simple app on the page https://docs.aspose.com/words/net
exists following code:

#!c:\python25\python.exe
import win32com.client
#Create instance of ComHelper class
helper = win32com.client.Dispatch("Aspose.Words.ComHelper")
#Open a template document
doc = helper.Open("C:\Temp\in.doc")

So my question is: How can I create or open document from Stream?
Thank you,
Valery

Hi

Thanks for your request. There is an overload of ComHelper.Open method, which accepts Stream as input parameter:
https://reference.aspose.com/words/net/aspose.words/comhelper/open/

Also, you can always create your own wrapper class, which can achieve this.

Hope this helps.

Best regards.

Thanks for your answer,
But I know I can open document from stream look at my code:

public void insertIntoWord(string textFileName, Stream streamFileName, ref MemoryStream outputFile)
{

    //Create docuemnt and DocuentBuilder
    Document doc = new Document(streamFileName);
    [//Aspose.Words.ComHelper](//Aspose.Words.ComHelper) HLP = new ComHelper();
        //doc = HLP.Open(streamFileName);
    DocumentBuilder builder = new DocumentBuilder(doc);
    //Create shape
    Aspose.Words.Drawing.Shape shape = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image);
    //Set paht to the linked image 
    shape.ImageData.SourceFullName = "<http://www.aspose.com/Images/aspose-logo.jpg>";
    //Set size of the image 
    shape.Height = 75;
    shape.Width = 188;
    //Inset image into teh docuemnt
    builder.InsertNode(shape);
    //Save output document
    doc.Save("out\_" + textFileName);
    doc.Save(outputFile, SaveFormat.Doc);

}

So I wrapped my project into COM.

In python code I want to open some file and send to COM stream with file’s content.

fileinput=open(‘c:\out.txt’,‘rb’)
streaminput= fileinput.read()
fileout=open(’’)

streamout = fileout.read()
doc= win32com.client.Dispatch(‘OfficeDocumentsHandler’) 
returned\_value=doc.insertIntoWord( textFileName, streaminput, streamout )

In C# code (see code above) I declared outfile as MemoryStream and streaminput as Stream.
When I run python code I take next error:
TypeError: The Python instance can not be converted to a COM object
Could you tell me what kind of object in python I need to use which are similar stream object in C#.
Thank you again
Valera

Hi

Thanks for your request. Maybe, you can try using ADODB.Stream in your case. For instance:

Dim fileStream
Set fileStream = CreateObject("ADODB.Stream")

Hope this helps.

Best regards.

Hi (privet),
I asked you how to represent C# stream and memorystrem objects into python;s objects. C# code works fine and I want to interact with C# code from python.
And I want to know how to send content of some file to C# code (COM).
To clear my question I need help from guy how is good at .net and python.
Valera

Hi

Thanks for your request. There is no way to use MemoryStream in COM. That is why I suggested you using ADODB.Stream.

stream = win32com.client.Dispatch("ADODB.Stream")

Also, maybe you can pass byte array as a parameter instead of stream.

Best regards.