This project has moved. For the latest updates, please go here.

Get Access to Textbox (Drawing)

Oct 8, 2010 at 1:15 PM

Hello,

My Problem is - i use a Template File. In this template is a Textbox (Product), wich is need to be filled.

So The Problem is, what way is there to get Access to is.

// My Worksheet

ExcelWorksheet ws = p.Workbook.Worksheets[1];

 ws.Drawings. ..... Or ws.Drawings.DrawingXml...

I Don't know.

 

Maybe u can Help me.

Greetings

Oct 9, 2010 at 3:20 AM

Hi,

Somehow felt this was a upcoming problem for me also so had a quick look.

Found Drawings.ExcelDrawings.AddDrawings() only checked the //xdr:twoCellAnchor nodes.

Not certain if this is the correct way to handle textboxs but by changing to

-------------8<-----------------------------------

        private void AddDrawings()
        {
            string[] _selectNodes = { "//xdr:oneCellAnchor", "//xdr:twoCellAnchor" };

            foreach (string sn in _selectNodes)
            {
                XmlNodeList list = _drawingsXml.SelectNodes(sn, NameSpaceManager);

                foreach (XmlNode node in list)
                {
                    ExcelDrawing dr = ExcelDrawing.GetDrawing(this, node);
                    _drawings.Add(dr);
                    if (!_drawingNames.ContainsKey(dr.Name.ToLower()))
                    {
                        _drawingNames.Add(dr.Name.ToLower(), _drawings.Count - 1);
                    }
                }

                list = null;
            }

-------------8<-----------------------------------

I can access a textbox with

-------------8<-----------------------------------

 using (ExcelPackage package = new ExcelPackage(newFile, templateFile))
                {
                    foreach (ExcelWorksheet ws in package.Workbook.Worksheets)
                    {
                        listBox1.Items.Add("Worksheet.Name: "+ ws.Name);
                        foreach (ExcelDrawing dw in ws.Drawings)
                        {
                            string dwType = dw.GetType().ToString();
                            string dwName = dw.Name.ToString();
                           
                            listBox1.Items.Add("    Drawing.Name: " + dw.Name);

                            var rt = (ws.Drawings[dw.Name] as ExcelShape);
                            {
                                if (rt != null) // not a ExcelShape
                                {
                                    listBox1.Items.Add("        Drawing.Text: " + rt.Text);
                                }
                            }
                        }
                    }

                    // save our new workbook and we are done!
                    package.Save();
                    templateFile = null;
                }

-------------8<-----------------------------------

My apologies for not using 'Insert Snippet'. Wouldn't work in my firefox? noscript blocking XSS I think.

 

James