Quantcast
Channel: Open XML Format SDK forum
Viewing all 1288 articles
Browse latest View live

Coloring cells in excel sheet using openXML in C#

$
0
0

Hi,

Please explain, how to color the two different cells (C4,F6) with two different colors in the excel sheet using OpenXML in C#.

thanks,

Elangovan P

 


How to get the embedded objects information (data range in embedded excel file) from word 2007 document using open xml sdk.

$
0
0

We can get the data range in excel sheet for a linked object in word and need to get the similar data for embedded objects in word?

I am able to get the embedded object file name in the folder named "word/embeddings/excelfilename".

Please help

Generating A Word 2010 Document based on XML File

$
0
0

Hello frnds 

I am having an large XML file generated on servers containing the information like SAN, HOSTNAME,IP's, WWN . . etc.

My plan is to convert this XML report in to word format i.e, on Word 2010 .docx file. For this I gon through the link

http://msdn.microsoft.com/en-us/library/ee872374(office.12).aspx and along with the video shown in this link explained in simple way and clear cut information for each stages like   XML->XSLT->WORD DOCUMENT

And here they used word 2007 ver to generate the report

The problem which am facing when going through the same steps .. Is am unable to come with the solution based on my XML file, am getting that word file but without any output when am running the solution file based on source file i.e, XML and XSLT.

 
And its a very large XML file it includes nearly 10 servers details in one XML file.
 
The example they took in the above link is very simple but mine is its real server report ..
 
I gon through in detail to build my document as they done, but am still unable to generate the report ..
 
If u go through that video, you will come to know its just a 9min video
 
I'll paste some XML code here .. [as I don't know how to attach the file with this post]   
 
Please let me know if any one have any idea how to workout with this kind of large XML file ..
Friends, I really need your suggestions ..

<SAN:SAN type="Category">
<SAN:Servers type="Container">
<SAN:Server type="Category">
<SAN:HostName type="Property">INKADCPCONT.lvgi.com</SAN:HostName>
<SAN:HostIPAddress type="Property">10.134.11.122</SAN:HostIPAddress>
<SAN:HostID type="Property">c867d384-48f3-4d5e-8d8e-1dc02febfe06</SAN:HostID>
<SAN:WWN type="Property">c867d384-48f3-4d5e-8d8e-1dc02febfe06</SAN:WWN>
<SAN:OSName type="Property">Windows Server 2008 R2 family</SAN:OSName>
<SAN:IsManuallyRegistered type="Property">false</SAN:IsManuallyRegistered>
<SAN:IsExpandable type="Property">false</SAN:IsExpandable>
<SAN:PollType type="Property">4</SAN:PollType>
<SAN:IfServerSupportSmartPoll type="Property">true</SAN:IfServerSupportSmartPoll>
<SAN:NumberOfLUNs type="Property">1</SAN:NumberOfLUNs>
<SAN:IsManaged type="Property">true</SAN:IsManaged>
<SAN:OSVersionAsString type="Property">6.1 (Build 7601) Service Pack 1.</SAN:OSVersionAsString>
<SAN:PlatformName type="Property">Windows NT</SAN:PlatformName>
<SAN:HBAInfo type="Category">
<SAN:NumberOfHBAPorts type="Property">2</SAN:NumberOfHBAPorts>
<SAN:HostLoginStatus type="Property">0</SAN:HostLoginStatus>
<SAN:HostManagementStatus type="Property">2</SAN:HostManagementStatus>
<SAN:IsAttachedHost type="Property">true</SAN:IsAttachedHost>
<SAN:LoggedInPorts type="PropertyArray">
<SAN:LoggedInPort type="Property">3</SAN:LoggedInPort>
<SAN:LoggedInPort type="Property">0</SAN:LoggedInPort>
<SAN:LoggedInPort type="Property">2</SAN:LoggedInPort>
<SAN:LoggedInPort type="Property">1</SAN:LoggedInPort>
</SAN:LoggedInPorts>
 


Thank you


praveen bellary.

OpenXML: add image in PowerPoint

$
0
0

Hi there, I need your appreciated help.

I need insert to the powerpoint presentation this image generate with chart control.

I try use the object Microsoft.Office.Interop.PowerPoint.Application but create problems in execution in the server.

I think use the OpenXML, but I dont'have idea... can you help me?

Thanks in advance.

<%@ Page Title="Home page" Language="C#" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><%@ Import Namespace="Microsoft.Office.Interop.PowerPoint" %><%@ Import Namespace="Microsoft.Office.Core" %><%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"><title>Grafico</title><script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
        string PNG = @"C:\\Inetpub\\wwwroot\\public\\chart.png";
        Chart1.Series["Default"].ChartType = SeriesChartType.Column;
        Chart1.Series["Default"]["PointWidth"] = "0.3";
        Chart1.Series["Default"].IsValueShownAsLabel = true;
        Chart1.Series["Default"]["BarLabelStyle"] = "Center";
        Chart1.Series["Default"]["PixelPointDepth"] = "20";
        Chart1.Series["Default"]["DrawingStyle"] = "Cylinder";
        Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 10;
        Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
        this.Chart1.SaveImage(PNG, ChartImageFormat.Png);


    }


</script></head><body><form id="form1" runat="server"><div><asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" Width="600px"><Series><asp:Series Name="Default" XValueMember="count" YValueMembers="ID"></asp:Series></Series><ChartAreas><asp:ChartArea Name="ChartArea1"></asp:ChartArea></ChartAreas></asp:Chart><asp:SqlDataSource ID="SqlDataSource1" runat="server" 
         ConnectionString="<%$ ConnectionStrings:ConnMySQL %>"
         ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>"
         SelectCommand="SELECT * FROM tbl_x"></asp:SqlDataSource></div></form></body></html>

OpenXml : PowerPoint . Add an Image and a Title into a Slide

$
0
0

Hi all,
I'm using OpenXml for the first time  and  I've tried  for several days to create a simple presentation in c#.

my goal is: given a list of images as input ,create for each one a slide with a title (image name ) and the image as picture.

Currently I can create either  a slide with just a title or a slide with just the image, but I'm not able to create one with both the elements :-)

Can you help me please ?

Thanks in Advance

Davide

   

OpenXML: add image dynamically from excel workbook to PowerPoint presentation

$
0
0

Hi,

i inserted image in the presentation file using the below code.

but i get this error.

After repairing it i am able to see image presented in the powerpoint presentation.

please help me in resolving this error.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Presentation; using P = DocumentFormat.OpenXml.Presentation; using D = DocumentFormat.OpenXml.Drawing; using DocumentFormat.OpenXml.Drawing; using System.IO; using DocumentFormat.OpenXml.Office2010.Drawing; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender,EventArgs e) { string filepath = @"C:\********\image1.pptx"; CreatePresentation(filepath); } private void CreatePresentation(string filepath) { PresentationDocument presentationDoc = PresentationDocument .Create(filepath, PresentationDocumentType.Presentation); PresentationPart presentationPart = presentationDoc .AddPresentationPart(); presentationPart.Presentation = new Presentation(); CreatePresentationParts(presentationPart); presentationDoc.Close(); } private void CreatePresentationParts(PresentationPart presentationPart) { SlideMasterIdList slideMasterIdList1 = new SlideMasterIdList( new SlideMasterId() { Id = (UInt32Value)2147483648U, RelationshipId = "rId1" }); SlideIdList slideIdList1 = new SlideIdList(new SlideId() { Id = (UInt32Value)256U, RelationshipId = "rId2" }); SlideSize slideSize1 = new SlideSize() { Cx = 9144000, Cy = 6858000, Type = SlideSizeValues.Screen4x3 }; NotesSize notesSize1 = new NotesSize() { Cx = 6858000, Cy = 9144000 }; DefaultTextStyle defaultTextStyle1 = new DefaultTextStyle(); presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1); SlidePart slidePart1; SlideLayoutPart slideLayoutPart1; SlideMasterPart slideMasterPart1; ThemePart themePart1; slidePart1 = CreateSlidePart(presentationPart); slideLayoutPart1 = CreateSlideLayoutPart(slidePart1); slideMasterPart1 = CreateSlideMasterPart(slideLayoutPart1); themePart1 = CreateTheme(slideMasterPart1); slideMasterPart1.AddPart(slideLayoutPart1, "rId1"); presentationPart.AddPart(slideMasterPart1, "rId1"); presentationPart.AddPart(themePart1, "rId5"); } private ThemePart CreateTheme(SlideMasterPart slideMasterPart1) { ThemePart themePart1 = slideMasterPart1 .AddNewPart<themepart>("rId5"); D.Theme theme1 = new D.Theme() { Name = "Office Theme" }; D.ThemeElements themeElements1 = new D.ThemeElements( new D.ColorScheme( new D.Dark1Color(new D.SystemColor() { Val = D.SystemColorValues.WindowText, LastColor = "000000" }), new D.Light1Color(new D.SystemColor() { Val = D.SystemColorValues.Window, LastColor = "FFFFFF" }), new D.Dark2Color(new D.RgbColorModelHex() { Val = "1F497D" }), new D.Light2Color(new D.RgbColorModelHex() { Val = "EEECE1" }), new D.Accent1Color(new D.RgbColorModelHex() { Val = "4F81BD" }), new D.Accent2Color(new D.RgbColorModelHex() { Val = "C0504D" }), new D.Accent3Color(new D.RgbColorModelHex() { Val = "9BBB59" }), new D.Accent4Color(new D.RgbColorModelHex() { Val = "8064A2" }), new D.Accent5Color(new D.RgbColorModelHex() { Val = "4BACC6" }), new D.Accent6Color(new D.RgbColorModelHex() { Val = "F79646" }), new D.Hyperlink(new D.RgbColorModelHex() { Val = "0000FF" }), new D.FollowedHyperlinkColor(new D.RgbColorModelHex() { Val = "800080" })) { Name = "Office" }, new D.FontScheme( new D.MajorFont( new D.LatinFont() { Typeface = "Calibri" }, new D.EastAsianFont() { Typeface = "" }, new D.ComplexScriptFont() { Typeface = "" }), new D.MinorFont( new D.LatinFont() { Typeface = "Calibri" }, new D.EastAsianFont() { Typeface = "" }, new D.ComplexScriptFont() { Typeface = "" })) { Name = "Office" }, new D.FormatScheme( new D.FillStyleList( new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }), new D.GradientFill( new D.GradientStopList( new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 37000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 35000 }, new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 15000 }, new D.SaturationModulation() { Val = 350000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 100000 } ), new D.LinearGradientFill() { Angle = 16200000, Scaled = true }), new D.NoFill(), new D.PatternFill(), new D.GroupFill()), new D.LineStyleList( new D.Outline( new D.SolidFill( new D.SchemeColor( new D.Shade() { Val = 95000 }, new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }), new D.PresetDash() { Val = D.PresetLineDashValues.Solid }) { Width = 9525, CapType = D.LineCapValues.Flat, CompoundLineType = D.CompoundLineValues.Single, Alignment = D.PenAlignmentValues.Center }, new D.Outline( new D.SolidFill( new D.SchemeColor( new D.Shade() { Val = 95000 }, new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }), new D.PresetDash() { Val = D.PresetLineDashValues.Solid }) { Width = 9525, CapType = D.LineCapValues.Flat, CompoundLineType = D.CompoundLineValues.Single, Alignment = D.PenAlignmentValues.Center }, new D.Outline( new D.SolidFill( new D.SchemeColor( new D.Shade() { Val = 95000 }, new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }), new D.PresetDash() { Val = D.PresetLineDashValues.Solid }) { Width = 9525, CapType = D.LineCapValues.Flat, CompoundLineType = D.CompoundLineValues.Single, Alignment = D.PenAlignmentValues.Center }), new D.EffectStyleList( new D.EffectStyle( new D.EffectList( new D.OuterShadow( new D.RgbColorModelHex( new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })), new D.EffectStyle( new D.EffectList( new D.OuterShadow( new D.RgbColorModelHex( new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })), new D.EffectStyle( new D.EffectList( new D.OuterShadow( new D.RgbColorModelHex( new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false }))), new D.BackgroundFillStyleList( new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }), new D.GradientFill( new D.GradientStopList( new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }), new D.LinearGradientFill() { Angle = 16200000, Scaled = true }), new D.GradientFill( new D.GradientStopList( new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }), new D.LinearGradientFill() { Angle = 16200000, Scaled = true }))) { Name = "Office" }); theme1.Append(themeElements1); theme1.Append(new D.ObjectDefaults()); theme1.Append(new D.ExtraColorSchemeList()); themePart1.Theme = theme1; return themePart1; } private SlideMasterPart CreateSlideMasterPart(SlideLayoutPart slideLayoutPart1) { SlideMasterPart slideMasterPart1 = slideLayoutPart1 .AddNewPart<slidemasterpart>("rId1"); SlideMaster slideMaster = new SlideMaster( new CommonSlideData(new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title Placeholder 1" }, new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Title })), new P.ShapeProperties(), new P.TextBody( new BodyProperties(), new ListStyle(), new Paragraph())))), new P.ColorMap() { Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink }, new SlideLayoutIdList(new SlideLayoutId() { Id = (UInt32Value)2147483649U, RelationshipId = "rId1" }), new TextStyles(new TitleStyle(), new BodyStyle(), new OtherStyle())); slideMasterPart1.SlideMaster = slideMaster; return slideMasterPart1; } private SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1) { SlideLayoutPart slideLayoutPart1 = slidePart1 .AddNewPart<slidelayoutpart>("rId1"); SlideLayout slideLayout = new SlideLayout( new CommonSlideData(new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" }, new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties( new PlaceholderShape())), new P.ShapeProperties(), new P.TextBody( new BodyProperties(), new ListStyle(), new Paragraph(new EndParagraphRunProperties()))))), new ColorMapOverride(new MasterColorMapping())); slideLayoutPart1.SlideLayout = slideLayout; return slideLayoutPart1; } private SlidePart CreateSlidePart(PresentationPart presentationPart) { SlidePart slidePart1 = presentationPart .AddNewPart<slidepart>("rId2"); ImagePart imagePart = slidePart1 .AddNewPart<imagepart>("image/png", "rId2"); string filepath = @"C:\******\image1.PNG"; FileStream stream = new FileStream(filepath, FileMode.Open); imagePart.FeedData(stream); stream.Close(); slidePart1.Slide = new Slide( new CommonSlideData( new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" }, new P.NonVisualShapeDrawingProperties( new ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties( new PlaceholderShape())), new P.ShapeProperties(), new P.TextBody( new BodyProperties(), new ListStyle(), new Paragraph( new EndParagraphRunProperties() { Language = "en-US" }))))), new ColorMapOverride(new MasterColorMapping())); P.Picture picture = new P.Picture(); P.BlipFill blipFill = new P.BlipFill(); D.Blip blip = new D.Blip() { Embed = "rId2" }; Stretch stretch = new Stretch(); FillRectangle fillRectangle = new FillRectangle(); stretch.Append(fillRectangle); blipFill.Append(blip); blipFill.Append(stretch); BlipExtensionList blipExtensionList1 = new BlipExtensionList(); BlipExtension blipExtension1 = new BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }; UseLocalDpi useLocalDpi1 = new UseLocalDpi() { Val = false }; useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main"); blipExtension1.Append(useLocalDpi1); blipExtensionList1.Append(blipExtension1); blip.Append(blipExtensionList1); picture.Append(blipFill); P.ShapeProperties shapeProperties1 = new P.ShapeProperties(); D.Transform2D transform2D1 = new D.Transform2D(); D.Offset offset1 = new D.Offset() { X = 467544L, Y = 548680L }; D.Extents extents1 = new D.Extents() { Cx = 3743848L, Cy = 3886743L }; transform2D1.Append(offset1); transform2D1.Append(extents1); D.PresetGeometry presetGeometry1 = new D.PresetGeometry() { Preset = D.ShapeTypeValues.Rectangle }; D.AdjustValueList adjustValueList1 = new D.AdjustValueList(); presetGeometry1.Append(adjustValueList1); shapeProperties1.Append(transform2D1); shapeProperties1.Append(presetGeometry1); picture.Append(shapeProperties1); slidePart1.Slide.CommonSlideData.ShapeTree.Append(picture); return slidePart1; } }

Thanks in advance !!

Banupriya



banupriya


insert paragraph of texts in the powerpoint slide dynamically using openxml

$
0
0

Hi ,

i am new to open xml. i have some requirement for my project.

i need to insert text or paragraphs  in the powerpoint slide dynamically that is coming from excel sheet .

Excel is the source document which contains texts and paragraphs.

For example : sheet 1 contains the following information. i need to retrieve these informations and write it into the powerpoint presentation. if the text limit reaches the end of the slide it should automatically create a new slide.

Currently am able to read all the contents from excel sheet and i could load in the dataset. after loading the content in the dataset i dont know how to write the loaded contents in the presentation slide.

i created an empty presentation using openxml with PresentationParts,SlidePart,SlideLayoutPart,SlideMasterPart,Theme.

My Code:

public void generate_click(object sender, EventArgs e)
        {
            string scode = "C:\\Users\\302480\\Documents\\Visual Studio 2010\\Projects\\ppt\\ppt\\Source\\Excel_Source_ppt\\test.pptx";
            CreatePresentation(scode);
            sExcelPath = Server.MapPath("~/Source/Excel_Source_ppt/") + ConfigurationManager.AppSettings["TEMS_ppt"].ToString();
            sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sExcelPath + ".xlsx;Extended Properties=Excel 12.0";
            Get_WorkSheet_Names();
            Get_Excel_Data();
            foreach (DataTable table in dsSOW.Tables)
            {
                foreach (DataRow dr in table.Rows)
                {
                    no = dr.ItemArray[0].ToString();
                    desc = dr.ItemArray[1].ToString();
                    data = no+ " " + desc;
                }
            }
private void Get_WorkSheet_Names()
        {
            string sWorkSheetsColl = String.Empty;
                {
                    int iIndex = 0;
                    oConn = new OleDbConnection(sConnString);
                    oConn.Open();
                    dtList = oConn.GetSchema("Tables");
                    if (dtList != null)
                    {
                        dsSOW = new DataSet();                       
                        foreach (DataRow dr in dtList.Rows)
                        {
                            if (dr["TABLE_NAME"].ToString().ToLower() != "_xlnm#_filterdatabase")
                            {
                                dsSOW.Tables.Add(dr["TABLE_NAME"].ToString());                               
                                sWorkSheetsColl += dr["TABLE_NAME"].ToString() + ",";
                                iIndex++;
                            }
                        }
                        sWorkSheetsColl = sWorkSheetsColl.TrimEnd(',');
                        sWorkSheets = sWorkSheetsColl.Split(',');
                        dsSOW.AcceptChanges();
                    }
                }
            }
        private void Get_Excel_Data()
        {
                for (int i = 0; i < sWorkSheets.Length; i++)
                {
                    oCmd = new OleDbCommand("SELECT * FROM [" + sWorkSheets[i].TrimEnd() + "]", oConn);
                    oDa = new OleDbDataAdapter();
                    oDa.SelectCommand = oCmd;
                    oDa.Fill(dsSOW.Tables[sWorkSheets[i].ToString()]);
                }
                oConn.Close();
                dsSOW.AcceptChanges();
         }     

 

 

public static void CreatePresentation(string filepath) { // Create a presentation at a specified file path. The presentation document type is pptx, by default. PresentationDocument presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation); PresentationPart presentationPart = presentationDoc.AddPresentationPart(); presentationPart.Presentation = new Presentation(); CreatePresentationParts(presentationPart); // Close the presentation handle presentationDoc.Close(); } private static void CreatePresentationParts(PresentationPart presentationPart) { SlideMasterIdList slideMasterIdList1 = new SlideMasterIdList(new SlideMasterId() { Id = (UInt32Value)2147483648U, RelationshipId = "rId1" }); SlideIdList slideIdList1 = new SlideIdList(new SlideId() { Id = (UInt32Value)256U, RelationshipId = "rId2" }); SlideSize slideSize1 = new SlideSize() { Cx = 9144000, Cy = 6858000, Type = SlideSizeValues.Screen4x3 }; NotesSize notesSize1 = new NotesSize() { Cx = 6858000, Cy = 9144000 }; DefaultTextStyle defaultTextStyle1 = new DefaultTextStyle(); presentationPart.Presentation.Append(slideMasterIdList1, slideIdList1, slideSize1, notesSize1, defaultTextStyle1); SlidePart slidePart1; SlideLayoutPart slideLayoutPart1; SlideMasterPart slideMasterPart1; ThemePart themePart1; slidePart1 = CreateSlidePart(presentationPart); slideLayoutPart1 = CreateSlideLayoutPart(slidePart1); slideMasterPart1 = CreateSlideMasterPart(slideLayoutPart1); themePart1 = CreateTheme(slideMasterPart1); slideMasterPart1.AddPart(slideLayoutPart1, "rId1"); presentationPart.AddPart(slideMasterPart1, "rId1"); presentationPart.AddPart(themePart1, "rId5"); } private static SlidePart CreateSlidePart(PresentationPart presentationPart) { SlidePart slidePart1 = presentationPart.AddNewPart<SlidePart>("rId2"); ImagePart imagePart = slidePart1.AddNewPart<ImagePart>("image/jpg", "rId2"); string filepath = @"C:\Users\302480\Documents\Visual Studio 2010\Projects\ppt\ppt\Source\Images\DDT.jpg"; FileStream stream = new FileStream(filepath, FileMode.Open); imagePart.FeedData(stream); stream.Close(); slidePart1.Slide = new Slide( new CommonSlideData( new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" }, new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape())), new P.ShapeProperties(), new P.TextBody( new BodyProperties(), new ListStyle(), new Paragraph(new EndParagraphRunProperties() { Language = "en-US" }))))), new ColorMapOverride(new MasterColorMapping())); P.Picture picture = new P.Picture(); P.BlipFill blipFill = new P.BlipFill(); D.Blip blip = new D.Blip() { Embed = "rId2" }; Stretch stretch = new Stretch(); FillRectangle fillRectangle = new FillRectangle(); stretch.Append(fillRectangle); blipFill.Append(blip); blipFill.Append(stretch); BlipExtensionList blipExtensionList1 = new BlipExtensionList(); BlipExtension blipExtension1 = new BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" }; UseLocalDpi useLocalDpi1 = new UseLocalDpi() { Val = false }; useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main"); blipExtension1.Append(useLocalDpi1); blipExtensionList1.Append(blipExtension1); blip.Append(blipExtensionList1); picture.Append(blipFill); P.ShapeProperties shapeProperties1 = new P.ShapeProperties(); D.Transform2D transform2D1 = new D.Transform2D(); D.Offset offset1 = new D.Offset() { X = 667544L, Y = 648680L }; D.Extents extents1 = new D.Extents() { Cx = 5743848L, Cy = 4886743L }; transform2D1.Append(offset1); transform2D1.Append(extents1); D.PresetGeometry presetGeometry1 = new D.PresetGeometry() { Preset = D.ShapeTypeValues.Rectangle }; D.AdjustValueList adjustValueList1 = new D.AdjustValueList(); presetGeometry1.Append(adjustValueList1); shapeProperties1.Append(transform2D1); shapeProperties1.Append(presetGeometry1); picture.Append(shapeProperties1); slidePart1.Slide.CommonSlideData.ShapeTree.Append(picture); return slidePart1; } private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1) { SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart<SlideLayoutPart>("rId1"); SlideLayout slideLayout = new SlideLayout( new CommonSlideData(new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" }, new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape())), new P.ShapeProperties(), new P.TextBody( new BodyProperties(), new ListStyle(), new Paragraph(new EndParagraphRunProperties()))))), new ColorMapOverride(new MasterColorMapping())); slideLayoutPart1.SlideLayout = slideLayout; return slideLayoutPart1; } private static SlideMasterPart CreateSlideMasterPart(SlideLayoutPart slideLayoutPart1) { SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart<SlideMasterPart>("rId1"); SlideMaster slideMaster = new SlideMaster( new CommonSlideData(new ShapeTree( new P.NonVisualGroupShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" }, new P.NonVisualGroupShapeDrawingProperties(), new ApplicationNonVisualDrawingProperties()), new GroupShapeProperties(new TransformGroup()), new P.Shape( new P.NonVisualShapeProperties( new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title Placeholder 1" }, new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Title })), new P.ShapeProperties(), new P.TextBody( new BodyProperties(), new ListStyle(), new Paragraph())))), new P.ColorMap() { Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink }, new SlideLayoutIdList(new SlideLayoutId() { Id = (UInt32Value)2147483649U, RelationshipId = "rId1" }), new TextStyles(new TitleStyle(), new BodyStyle(), new OtherStyle())); slideMasterPart1.SlideMaster = slideMaster; return slideMasterPart1; } private static ThemePart CreateTheme(SlideMasterPart slideMasterPart1) { ThemePart themePart1 = slideMasterPart1.AddNewPart<ThemePart>("rId5"); D.Theme theme1 = new D.Theme() { Name = "Office Theme" }; D.ThemeElements themeElements1 = new D.ThemeElements( new D.ColorScheme( new D.Dark1Color(new D.SystemColor() { Val = D.SystemColorValues.WindowText, LastColor = "000000" }), new D.Light1Color(new D.SystemColor() { Val = D.SystemColorValues.Window, LastColor = "FFFFFF" }), new D.Dark2Color(new D.RgbColorModelHex() { Val = "1F497D" }), new D.Light2Color(new D.RgbColorModelHex() { Val = "EEECE1" }), new D.Accent1Color(new D.RgbColorModelHex() { Val = "4F81BD" }), new D.Accent2Color(new D.RgbColorModelHex() { Val = "C0504D" }), new D.Accent3Color(new D.RgbColorModelHex() { Val = "9BBB59" }), new D.Accent4Color(new D.RgbColorModelHex() { Val = "8064A2" }), new D.Accent5Color(new D.RgbColorModelHex() { Val = "4BACC6" }), new D.Accent6Color(new D.RgbColorModelHex() { Val = "F79646" }), new D.Hyperlink(new D.RgbColorModelHex() { Val = "0000FF" }), new D.FollowedHyperlinkColor(new D.RgbColorModelHex() { Val = "800080" })) { Name = "Office" }, new D.FontScheme( new D.MajorFont( new D.LatinFont() { Typeface = "Calibri" }, new D.EastAsianFont() { Typeface = "" }, new D.ComplexScriptFont() { Typeface = "" }), new D.MinorFont( new D.LatinFont() { Typeface = "Calibri" }, new D.EastAsianFont() { Typeface = "" }, new D.ComplexScriptFont() { Typeface = "" })) { Name = "Office" }, new D.FormatScheme( new D.FillStyleList( new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }), new D.GradientFill( new D.GradientStopList( new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 37000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 35000 }, new D.GradientStop(new D.SchemeColor(new D.Tint() { Val = 15000 }, new D.SaturationModulation() { Val = 350000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 100000 } ), new D.LinearGradientFill() { Angle = 16200000, Scaled = true }), new D.NoFill(), new D.PatternFill(), new D.GroupFill()), new D.LineStyleList( new D.Outline( new D.SolidFill( new D.SchemeColor( new D.Shade() { Val = 95000 }, new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }), new D.PresetDash() { Val = D.PresetLineDashValues.Solid }) { Width = 9525, CapType = D.LineCapValues.Flat, CompoundLineType = D.CompoundLineValues.Single, Alignment = D.PenAlignmentValues.Center }, new D.Outline( new D.SolidFill( new D.SchemeColor( new D.Shade() { Val = 95000 }, new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }), new D.PresetDash() { Val = D.PresetLineDashValues.Solid }) { Width = 9525, CapType = D.LineCapValues.Flat, CompoundLineType = D.CompoundLineValues.Single, Alignment = D.PenAlignmentValues.Center }, new D.Outline( new D.SolidFill( new D.SchemeColor( new D.Shade() { Val = 95000 }, new D.SaturationModulation() { Val = 105000 }) { Val = D.SchemeColorValues.PhColor }), new D.PresetDash() { Val = D.PresetLineDashValues.Solid }) { Width = 9525, CapType = D.LineCapValues.Flat, CompoundLineType = D.CompoundLineValues.Single, Alignment = D.PenAlignmentValues.Center }), new D.EffectStyleList( new D.EffectStyle( new D.EffectList( new D.OuterShadow( new D.RgbColorModelHex( new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })), new D.EffectStyle( new D.EffectList( new D.OuterShadow( new D.RgbColorModelHex( new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false })), new D.EffectStyle( new D.EffectList( new D.OuterShadow( new D.RgbColorModelHex( new D.Alpha() { Val = 38000 }) { Val = "000000" }) { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false }))), new D.BackgroundFillStyleList( new D.SolidFill(new D.SchemeColor() { Val = D.SchemeColorValues.PhColor }), new D.GradientFill( new D.GradientStopList( new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }), new D.LinearGradientFill() { Angle = 16200000, Scaled = true }), new D.GradientFill( new D.GradientStopList( new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }, new D.GradientStop( new D.SchemeColor(new D.Tint() { Val = 50000 }, new D.SaturationModulation() { Val = 300000 }) { Val = D.SchemeColorValues.PhColor }) { Position = 0 }), new D.LinearGradientFill() { Angle = 16200000, Scaled = true }))) { Name = "Office" }); theme1.Append(themeElements1); theme1.Append(new D.ObjectDefaults()); theme1.Append(new D.ExtraColorSchemeList()); themePart1.Theme = theme1; return themePart1; }


Thanks !

banu


banupriya


MS word integration with marklogic server

$
0
0

Hi,

Am new to this kind of integration between Ms word and marklogic server.Can some one help me with samples?


Read the value of checkbox from active*.bin file from excel

$
0
0

I am trying to read the value of form checkbox from excel file.

I could reach till the .bin part but i am somehow not able to find any solution for getting the value of checkbox and option button from bin file.

foreach (WorksheetPart wsp in sd.WorkbookPart.WorksheetParts)
                {

                    foreach (DocumentFormat.OpenXml.Spreadsheet.Control ctrl in wsp.Worksheet.Descendants<DocumentFormat.OpenXml.Spreadsheet.Control>())
                    {
                        EmbeddedControlPersistencePart part = wsp.GetPartById(ctrl.Id) as EmbeddedControlPersistencePart;

                        using (OpenXmlReader reader = OpenXmlReader.Create(part.GetStream()))
                        {
                            reader.Read();
                            OpenXmlElement controlDetails = reader.LoadCurrentElement();
                            classId = controlDetails.GetAttribute("classid", controlDetails.NamespaceUri).Value;
                        }

                        if (string.Compare(classId, checkBoxId) == 0 || string.Compare(classId, radioButtonId) == 0)
                        {
                            foreach (EmbeddedControlPersistenceBinaryDataPart ecpbPart in part.EmbeddedControlPersistenceBinaryDataParts)
                            {

                                Stream stream = ecpbPart.GetStream();

                                byte[] bufferConnectionsPart = new BinaryReader(stream).ReadBytes((int)stream.Length);

                                ?????

                            }
                        }
                    }                   
                }

Please suggest any solution or work around.

Understanding relationship between SlideParts and their NotesSlidePart

$
0
0

I am trying to determine the relationship between SlideParts and their NoteSlideParts counterpart. Our team can create these objects and populate them properly, whoever we cannot create a relationship joining them. We start with an original template powerpoint file which has a Notes section in it. Then we make a clone of the original ppt. (As to never modify the Template) in doing so we lose the relationship to the Clone. Any assistance please. Below is the code we are using to create the slide Template then the Note section. If we do not delete the original it displays.

var presentationPart = presentationDocument.PresentationPart;
var slideIds = presentationPart.Presentation.SlideIdList.ChildElements;
string relId = ((SlideId)slideIds[0]).RelationshipId;    
var slideTemplate = (SlidePart)presentationPart.GetPartById(relId);

IEnumerable<NotesSlidePart> note = presentationPart.SlideParts.Select(slide => slide.NotesSlidePart);
var notesSlideParts = note as IList<NotesSlidePart> ?? note.ToList();
CreateNotes(notesSlideParts.First());

var newSlide = CloneSlide(presentationPart, slideTemplate, i);    

DeleteSlide(presentationDocument, Zero); <--- This Line removes relationship
presentationPart.Presentation.Save();

Documentation of Changes made in Open XML File Format

$
0
0

Hi Folks,

I have made some changes in Open XML File Format using extension list. I'm able to use files without any issue as the extension list supports full fidelity in round-tripping & interoperability.

I wanted to understand the process of documenting this changes in the public & the legal implications if any.

Is there any standardization process for the same?

Any pointers around this will be highly appreciated.

Thanks, 

Could not load file or assembly DocumentFormat.OpenXml

$
0
0

Any help please? I get following Error when running an OpenXml application. I tried setting copy local = true for the reference. But that did not work.

Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

 

merging multiple docx files using open xml.

$
0
0

hi,

i want to merge  multible word docx files by using C# in openxml , plz can any one help me.

actually i tried with Altchunk but it throwing error like "document containing altchunk". so is there any other approach to fisx this problem.

thanks ,

in advance

How to restrict editing in word document using openxml

$
0
0

Guys,

I need to restrict editing on a word document. I've placed section breaks to define separate sections. Say I've defined five sections in the document and I want to protect section-2 and section-4 only. How I can do this using openXML sdk 2.0?

I've searched a lot on forums but couldn't find a solution for this scenario. There are lots of answers on document level protection, but I want to do it using openXML sdk.

Here is how we can do it manually:

http://www.officearticles.com/word/protecting_parts_of_a_document_in_microsoft_word.htm


Your help is highly appreciated.

Thanks


How to restrict editing in word document using openxml

Open XML SDK v2 Handling Multiple Threads

$
0
0

Hi

I have read a post or two that suggests the open XML sdk is not thread safe but I haven't found any official MS document that states this in fact to the contrary most online docs demonstrate how to use the SDK for serverside creation of office documents. I'm prototyping a windows service that reads MSMQ and dispatches a thread to export some data to excel using open xml sdk v2.  The thread is created by calling BeginInvoke on a delegate and ultimately calls this code:

using

(SpreadsheetDocument workBook =SpreadsheetDocument.Open(exportFileInfo.FullName,true))

{

 

WorkbookHelper workBookHelper =newWorkbookHelper(workBook.WorkbookPart, tableName);

exportRowCount =

this.DataBind(workBookHelper, datasource);

workBook.WorkbookPart.Workbook.Save();

workBook.Close();

 

 

return exportRowCount;

}

If I allow 2 or more threads to run concurrently:

  • The code never finishes when I try to export 10000 rows. (I suspect I'm getting deadlock but not sure how to verify this). 
  • It does work if I try to export 5000 rows or less.

If I comment out the calls to save() and close() the code always finishes no matter how many threads I allow to run.  If I allow just one thread to run the exports always works.

Is there a threading problem in the SDK related to saving and closing workbooks and if so is there a plan to fix it soon?

Other than synchronising the entire block of code above is there a way I can I fix the problem myself?

Regards







 


How can I use an SQL like statement to filter a row set when reading from a spread sheet

$
0
0

rather than reading every row on the sheet and comparing a cell value for interest .... I would prefer to use a select statement that returns a filtered row set ... is this possible?

e.g. if column 4 contains a value and I only want row sets that contain distict values (for counting) ...

I would use an SQL statement like: SELECT DISTINCT COL4 WHERE COL1 = '50' 


Tracey

Where are Microsoft headed with Office templates in Open XML SDK?

$
0
0

Hi

I have since a year back being forced to move my interop applications for Office document management in Windows server from Microsoft Office applications to Open XML SDK, as I'm sure is true for many other developers.

This has been a tough task, since no knowledge in Office object model has come to use in Open XML SDK.

One of the greatest disappointments is the lack of support for Office regular templates.

I have large companies as customers and one of the most important part in their management of documents, is the ability to control formats, building blocks and so on through templates.

Are Microsoft working with a fix to Open XML SDK to provide a way to create 100 % correct documents, spreadsheets and presentations from a template, or are the templates about to be obsolete?


Best Regards Peter Karlström Midrange AB, Sweden


Create mid range application to save word file into the server

$
0
0

Hi,

I came up with a following scenario of creating mid range application that

1.To find the version of the document from the server

2. when the user edit/modify the content and clicks on save the previous versions should be combined into a new word document and saved back to server as the latest version.

Kindly help me with guide /samples.


Convert Word Processing Document to DOCX file

$
0
0

Hi,

Since I am new to this OpenXML, and as I am working on populating the OpenXML document programmatically using Open XML Power tools utility class as mentioned below, the objective of the is to search for the tag and replace it with value, and save the document as docx so that this file can be used for further processing.

Please help me in converting Word Processing Document back to docx file after replacing the text.

/***********************BEGIN OF CODE**************************************/

var byteArray = File.ReadAllBytes("Sample.docx");

using (var memoryStream = new MemoryStream())
 {
   memoryStream.Write(byteArray, 0, byteArray.Length);

   using (var wordDoc = WordprocessingDocument.Open(memoryStream, true))
    {
      //This SearchAndReplace is utility class from OpenXMLPower Tools returns WordprocessingDocument after replacing the  text in the Word Processing Document
      //And the function signature is  WordprocessingDocument SearchAndReplace(WordprocessingDocument wordDoc, string search, string replace, bool matchCase)
      var processedDoc = TextReplacer.SearchAndReplace(wordDoc, "«FullName»", "George Smith", true);

      //I need to know how to convert this above processedDoc(of type WordprocessingDocument) to back to docx file, so that I can use it for futher processing.
    }
 }

/**********************************END OF CODE*****************************/

FORMAT OF SAMPLE.DOCX

«FullName»,                                        

«CusStreet1», «CusStreet2»,

«CusCity»,«CusState»,«CusZip»,

Date: «DateToday»,

«ADDTEXT»,

/******************END OF FILE***************************/

Thanks in Advance.

OpenXMLSDK WordProcessing - Document getting corrupted after inseting an image.

$
0
0

Hi Guys,

I was trying to insert an image to a table cell in word document using OpenXMLSDK. After the code is run, when i try to open the output file (.docx) it gives and error saying'document cannot be opened ,there are  problem with the content',Details: Unspecified error Location:Part: /word/document.xml,line1 column 0'. and on click on ok i get the following message



On clicking Yes i'm able to retrieve the document and see the image i have inserted. I have followed the steps in

http://msdn.microsoft.com/en-us/library/bb497430.aspx

Public Sub FunctionWrite(ByVal sRecord As String, ByVal rHeader As String, ByVal rData As String, ByVal signaturePath As String)
Using doc As WordprocessingDocument = WordprocessingDocument.Open(sRecord, True)
                Dim mainPart As MainDocumentPart = doc.MainDocumentPart

                Dim imagePart As ImagePart = mainPart.AddImagePart(ImagePartType.Jpeg)
                Using stream As New FileStream(signaturePath, FileMode.Open)
                    imagePart.FeedData(stream)
                End Using
                For Each tb As DocumentFormat.OpenXml.Wordprocessing.Table In doc.MainDocumentPart.Document.Body.Elements(Of DocumentFormat.OpenXml.Wordprocessing.Table)().ToList()
                    For Each row As DocumentFormat.OpenXml.Wordprocessing.TableRow In tb.Elements(Of DocumentFormat.OpenXml.Wordprocessing.TableRow)().ToList()
                        For Each cell As DocumentFormat.OpenXml.Wordprocessing.TableCell In row.Elements(Of DocumentFormat.OpenXml.Wordprocessing.TableCell)().ToList()
                                    Dim cell2 As DocumentFormat.OpenXml.Wordprocessing.TableCell = row.Elements(Of DocumentFormat.OpenXml.Wordprocessing.TableCell)().ElementAt(3)

                                    cell2.Append(New Paragraph(New Run(New RunProperties(New NoProof()), RetImageElement(mainPart.GetIdOfPart(imagePart), signaturePath))))
                        Next
                    Next
                Next
            End Using
End Sub
Public Function RetImageElement(ByVal relationshipId As String, ByVal imagepath As String) As DocumentFormat.OpenXml.Wordprocessing.Drawing
        Dim result As String

        result = Path.GetFileName(imagepath)

        ' Define the reference of the image.
        Dim element = New Drawing( _
                              New DW.Inline( _
                          New DW.Extent() With {.Cx = 990000L, .Cy = 792000L}, _
                          New DW.EffectExtent() With {.LeftEdge = 0L, .TopEdge = 0L, .RightEdge = 0L, .BottomEdge = 0L}, _
                          New DW.DocProperties() With {.Id = CType(1UI, UInt32Value), .Name = "Picture1"}, _
                          New DW.NonVisualGraphicFrameDrawingProperties( _
                              New A.GraphicFrameLocks() With {.NoChangeAspect = True} _
                              ), _
                          New A.Graphic(New A.GraphicData( _
                                        New PIC.Picture( _
                                            New PIC.NonVisualPictureProperties( _
                                                New PIC.NonVisualDrawingProperties() With {.Id = 0UI, .Name = result}, _
                                                New PIC.NonVisualPictureDrawingProperties() _
                                                ), _
                                            New PIC.BlipFill( _
                                                New A.Blip( _
                                                    New A.BlipExtensionList( _
                                                        New A.BlipExtension() With {.Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"}) _
                                                    ) With {.Embed = relationshipId, .CompressionState = A.BlipCompressionValues.Print}, _
                                                New A.Stretch( _
                                                    New A.FillRectangle() _
                                                    ) _
                                                ), _
                                            New PIC.ShapeProperties( _
                                                New A.Transform2D( _
                                                    New A.Offset() With {.X = 0L, .Y = 0L}, _
                                                    New A.Extents() With {.Cx = 990000L, .Cy = 792000L}), _
                                                New A.PresetGeometry( _
                                                    New A.AdjustValueList() _
                                                    ) With {.Preset = A.ShapeTypeValues.Rectangle} _
                                                ) _
                                            ) _
                                        ) With {.Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"} _
                                    ) _
                                ) With {.DistanceFromTop = 0UI, _
                                        .DistanceFromBottom = 0UI, _
                                        .DistanceFromLeft = 0UI, _
                                        .DistanceFromRight = 0UI} _
                            )
        Return element
    End Function


I was trying to write to the 3rd element of the row that the reason i'm using ElementAt(3)




Viewing all 1288 articles
Browse latest View live