none
Excel 2007 PublishObjects not working with xlSourceChart RRS feed

  • Question

  • It seems that it is no more possible with 2007 to publish separate object from Excel sheet in c# :

              xlBook.PublishObjects.Add(ePublishType, sWebPage,
                                              pPubObj.sWorksheet, pPubObj.sObjectName,
                                              XlHtmlType.xlHtmlStatic, Missing.Value, sTitle).Publish(true);


        Give that : Exception from HRESULT: 0x800A03EC

    and also I am no more able to find how to do that manually with Excel 2007...

    But was working fine with older Excel...

    Thanks for your help

    Cook32
    • Changed type Tim Li Monday, December 15, 2008 2:26 AM customer no response, set to comment, sorry for any inconvenience
    • Changed type Cindy Meister MVPModerator Monday, December 15, 2008 8:18 AM OP has responded
    Monday, December 8, 2008 1:31 PM

Answers

  • Hi,

    Sorry I forget to add a precision, I have this problem with Charts not with Ranges : XlSourceType.xlChart

    Regards

    Cook
    • Marked as answer by Tim Li Thursday, December 18, 2008 3:35 AM
    Monday, December 15, 2008 8:06 AM
  • Hi ,

    The parameter Microsoft.Office.Interop.Excel.XlSourceType.xlSourceChart is not for the chart embedded in a Worksheet but for a Chart Sheet(which to create by select a cell and hit f11).

    We could not export a single chart in a Worksheet to a web page, and you could proof this form UI.In Excel 2003 we could achieve this, it's different from Excel 2007.

    Thanks
    • Marked as answer by Tim Li Thursday, December 18, 2008 3:35 AM
    Tuesday, December 16, 2008 6:54 AM
  • I found a solution :)

    So the best way is to move the chart to a new ChartSheet and to publish this new object...

                           ((Worksheet)xlBook.Sheets[pPubObj.sWorksheet]).Select(Missing.Value);
                            Worksheet oCurrentSheet = (Worksheet)oExcel.ActiveSheet;
                            ChartObject oChart = (ChartObject)oCurrentSheet.ChartObjects(pPubObj.sObjectName);
                            oChart.Activate();

                            Chart oNewChart = ((Chart)xlBook.ActiveChart).Location(XlChartLocation.xlLocationAsNewSheet, "_SheetTmp" + i);

                          
                            oNewChart.Activate();

                           xlBook.PublishObjects.Add(ePublishType, sWebPage,
                                                  "_SheetTmp" + i, "",
                                                  XlHtmlType.xlHtmlStatic, sTitle, sTitle).Publish(false);
     
    So now it is working but but but...The new problem is the size of the Chart.
    Because when moving in the new sheet, the size is really bigger.
    It is possible to resize it manually of course but I am trying to do that before Publishing.

    It seems forbidden to play with ChartArea Height and Width. So I am searching on Scaling but not sure.

    Thanks for your help

    Cook

    • Marked as answer by Tim Li Thursday, December 18, 2008 3:35 AM
    Tuesday, December 16, 2008 7:08 AM
  • Cook32 said:

    I found a solution :)

    So the best way is to move the chart to a new ChartSheet and to publish this new object...

    So now it is working but but but...The new problem is the size of the Chart.
    Because when moving in the new sheet, the size is really bigger.
    It is possible to resize it manually of course but I am trying to do that before Publishing.

    It seems forbidden to play with ChartArea Height and Width. So I am searching on Scaling but not sure.



    As best I recall, I think if you change the MARGIN settings for printing this sheet that the chart will resize to fit within the margins (which should carry over for publishing?)
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Tim Li Thursday, December 18, 2008 3:34 AM
    Tuesday, December 16, 2008 10:51 AM
    Moderator

All replies

  • Hi ,

    I've tried to reproduce your issue, but PublishObjects.Add method seems worked fine on my system,while I'm using Visual Studio 2008 and Excel 2007, the following is my code:
      void PublishObject()  
            {  
                Excel.Range rng = Application.Selection as Excel.Range;  
                rng = rng.get_Range(
    "A1""A11");
                rng.Cells[1, 1] = "50";  
                rng[2, 1] = "100";  
                rng[3, 1] = "70";  
                rng.Name = "MyRange";  
                Application.ActiveWorkbook.PublishObjects.Add(Microsoft.Office.Interop.Excel.XlSourceType.xlSourceRange, @"c:\desktop\Output.htm",  
                    this.Application.ActiveSheet, "MyRange", Excel.XlHtmlType.xlHtmlStatic, "MyDiv""MyTitle").Publish(true);  
            } 
    With this code, I could successfully get a htm file appears on my desktop.

    I've also noticed that ePublishType is your own variable, and we don't kown what does it mean. May be the problem is caused by the rest of the code?

    Thanks
    Thursday, December 11, 2008 9:55 AM
  • Hi,

    Sorry I forget to add a precision, I have this problem with Charts not with Ranges : XlSourceType.xlChart

    Regards

    Cook
    • Marked as answer by Tim Li Thursday, December 18, 2008 3:35 AM
    Monday, December 15, 2008 8:06 AM
  • Hi ,

    The parameter Microsoft.Office.Interop.Excel.XlSourceType.xlSourceChart is not for the chart embedded in a Worksheet but for a Chart Sheet(which to create by select a cell and hit f11).

    We could not export a single chart in a Worksheet to a web page, and you could proof this form UI.In Excel 2003 we could achieve this, it's different from Excel 2007.

    Thanks
    • Marked as answer by Tim Li Thursday, December 18, 2008 3:35 AM
    Tuesday, December 16, 2008 6:54 AM
  • I found a solution :)

    So the best way is to move the chart to a new ChartSheet and to publish this new object...

                           ((Worksheet)xlBook.Sheets[pPubObj.sWorksheet]).Select(Missing.Value);
                            Worksheet oCurrentSheet = (Worksheet)oExcel.ActiveSheet;
                            ChartObject oChart = (ChartObject)oCurrentSheet.ChartObjects(pPubObj.sObjectName);
                            oChart.Activate();

                            Chart oNewChart = ((Chart)xlBook.ActiveChart).Location(XlChartLocation.xlLocationAsNewSheet, "_SheetTmp" + i);

                          
                            oNewChart.Activate();

                           xlBook.PublishObjects.Add(ePublishType, sWebPage,
                                                  "_SheetTmp" + i, "",
                                                  XlHtmlType.xlHtmlStatic, sTitle, sTitle).Publish(false);
     
    So now it is working but but but...The new problem is the size of the Chart.
    Because when moving in the new sheet, the size is really bigger.
    It is possible to resize it manually of course but I am trying to do that before Publishing.

    It seems forbidden to play with ChartArea Height and Width. So I am searching on Scaling but not sure.

    Thanks for your help

    Cook

    • Marked as answer by Tim Li Thursday, December 18, 2008 3:35 AM
    Tuesday, December 16, 2008 7:08 AM
  • Cook32 said:

    I found a solution :)

    So the best way is to move the chart to a new ChartSheet and to publish this new object...

    So now it is working but but but...The new problem is the size of the Chart.
    Because when moving in the new sheet, the size is really bigger.
    It is possible to resize it manually of course but I am trying to do that before Publishing.

    It seems forbidden to play with ChartArea Height and Width. So I am searching on Scaling but not sure.



    As best I recall, I think if you change the MARGIN settings for printing this sheet that the chart will resize to fit within the margins (which should carry over for publishing?)
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Tim Li Thursday, December 18, 2008 3:34 AM
    Tuesday, December 16, 2008 10:51 AM
    Moderator