Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > C# и OpenOffice


Автор: serghey 25.4.2007, 11:23
есть большая проблема:
хочу подрубить openoffice к приложению:
для этого сделал:
класс:

Код

class MyFrameActionListener : XFrameActionListener
    {
       
        public void frameAction(FrameActionEvent Action)
        {
            //if (Action.Action == FrameAction.FRAME_UI_ACTIVATED)
            //    MessageBox.Show("FrameEvent FRAME_UI_ACTIVATED");
            //else if (Action.Action == FrameAction.FRAME_ACTIVATED)
            //    MessageBox.Show("FrameEvent FRAME_ACTIVATED");
            
            
            //else if (Action.Action == FrameAction.CONTEXT_CHANGED)
            //    MessageBox.Show("FrameEvent CONTEXT_CHANGED");
            //    //If these occours, the file is complete loaded 
            //else if (Action.Action == FrameAction.COMPONENT_ATTACHED)
            //    MessageBox.Show("FrameEvent COMPONENT_ATTACHED");
            //else if (Action.Action == FrameAction.COMPONENT_REATTACHED)
            //    MessageBox.Show("FrameEvent COMPONENT_DEATTACHED");
            //else if (Action.Action == FrameAction.FRAME_DEACTIVATING)
            //    MessageBox.Show("FrameEvent FRAME_DEACTIVATING");
               
            //else if (Action.Action == FrameAction.COMPONENT_DETACHING)
            //вставка 
            if (Action.Action == FrameAction.COMPONENT_DETACHING)
            {
                
                
            }
        }
        
        
        public void disposing(unoidl.com.sun.star.lang.EventObject Source)
        {

            byte[] document;
            FileStream fs = new FileStream(@"D:\test7.odt", FileMode.Open, FileAccess.Read);
            document = new byte[fs.Length];
            fs.Read(document, 0, document.Length);
            
            string source = @"Data source=sergm\sergm;" +
                    "Initial Catalog=document; Integrated security=SSPI";
            SqlConnection sqlcon = new SqlConnection(source);
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand("i_template", sqlcon);
            sqlcom.CommandType = CommandType.StoredProcedure;
            sqlcom.Parameters.Add("@doc", SqlDbType.VarBinary).Value = fs;
            sqlcom.ExecuteNonQuery();

            sqlcon.Close();
            sqlcon.Dispose();
            
        }
для обработки событий фрейма.
программа:
static XComponent initDocument(
         XComponentLoader aLoader, string file, string target
         )
        {
            XComponent xComponent = aLoader.loadComponentFromURL(
               file, target, 0,
               new PropertyValue[0]);

            return xComponent;
        }



        private static string PathConverter(string file)
        {
            try
            {
                file = file.Replace(@"\", "/");

                return "file:///" + file;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
private void bt_add_Click(object sender, EventArgs e)
        {//организация формы-контейнера для содержания в ней окна приложения OO
            Form frm_doc = new Form();
            frm_doc.Width = 500;
            frm_doc.Height = 500;
            frm_doc.IsMdiContainer=true;
            frm_doc.Show();

            
            
            if (File.Exists(@"D:\test7.odt"))
                File.Delete(@"D:\test7.odt");

            File.Copy(@"D:\null.odt", @"D:\test7.odt");
            XComponentContext xlocalContext;
            xlocalContext = uno.util.Bootstrap.bootstrap();

            XMultiServiceFactory xRemoteFactory;
            xRemoteFactory = (XMultiServiceFactory)
                             xlocalContext.getServiceManager();

            XComponentLoader aLoader;
            aLoader = (XComponentLoader)xRemoteFactory.createInstance(
                                            "com.sun.star.frame.Desktop");

            XComponent xComponent;
            xComponent = initDocument(aLoader, "private:factory/swriter", "_blank");

            XFrame xframe = ((XDesktop)aLoader).getCurrentFrame();
            xframe.addFrameActionListener(new MyFrameActionListener());
            initDocument(((XComponentLoader)xframe),
                         PathConverter(@"D:\test7.odt"),
                         "_self");
            
             
        }


проблема состоит в том, что после считывания файла из БД на диск я не могу открыть файл
выдает сообщение о том что файл поврежден, после восстановления он открывается причем полностью, но сей факт неудобен, подскажите люди добрые, кто чем может

Автор: Exception 25.4.2007, 17:39
Модератор: Используйте кнопку "Код"!

Отредактируйте, пожалуйста, ваше сообщение!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)