Beispiel #1
0
 /// <summary>
 /// 替换文字内容
 /// </summary>
 /// <param name="sheet"></param>
 /// <param name="groupJTSYQ"></param>
 /// <param name="xmlobjectDic"></param>
 public static void ReplaceTextByXMLObject(ISheet sheet, object obj, Dictionary <string, XMLObject> xmlobjectDic)
 {
     foreach (IRow row in sheet)
     {
         foreach (ICell cell in row)
         {
             if (cell.CellType == CellType.String)
             {
                 string cellValue = cell.StringCellValue;
                 if (cellValue.Contains("["))
                 {
                     foreach (string method in xmlobjectDic.Keys)
                     {
                         if (cellValue.Contains(method))
                         {
                             Object value = XMLRead.GetObjectMethodResult(xmlobjectDic[method], obj);
                             if (value != null)
                             {
                                 cellValue = cellValue.Replace("[" + method + "]", value.ToString());
                             }
                             else
                             {
                                 cellValue = cellValue.Replace("[" + method + "]", "");
                             }
                             cell.SetCellValue(cellValue);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 对象写入 row
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="row"></param>
 /// <param name="xmlDic"></param>
 public static void WriteRowObject(object obj, IRow row, Dictionary <int, XMLObject> xmlDic)
 {
     foreach (int index in xmlDic.Keys)
     {
         XMLObject xmlObject = xmlDic[index];
         object    result    = XMLRead.GetObjectMethodResult(xmlObject, obj);
         SetValue(row, index, result);
     }
 }
Beispiel #3
0
        public static void ReplaceText(object obj, Dictionary <string, XMLObject> clazzDic, MapDocumentClass mapDocument)
        {
            ArcGisUtils.axPageLayoutControl.PageLayout = mapDocument.PageLayout;
            var       graphicsContainer = ArcGisUtils.axPageLayoutControl.GraphicsContainer;
            XMLObject xmlObject;
            IElement  element = graphicsContainer.Next();

            while (element != null)
            {
                if (element is ITextElement)
                {
                    ITextElement textElement = (ITextElement)element;
                    string       text        = textElement.Text;
                    int          start       = text.IndexOf("[");
                    if (start != -1)
                    {
                        string key = text.Substring(start + 1, text.IndexOf("]") - start - 1);
                        if (clazzDic.TryGetValue(key, out xmlObject))
                        {
                            object value = XMLRead.GetObjectMethodResult(xmlObject, obj);
                            if (value != null)
                            {
                                textElement.Text = text.Replace("[" + key + "]", value.ToString());
                            }
                            else
                            {
                                textElement.Text = text.Replace("[" + key + "]", "");
                            }
                            graphicsContainer.UpdateElement((IElement)textElement);
                        }
                    }
                }

                element = graphicsContainer.Next();
            }
        }
Beispiel #4
0
        public static void WriteObjects <T>(ISheet sheet, XMLTable xmlTable, IList <T> objects)
        {
            IList <string> errors             = new List <string>();
            int            rowStart           = xmlTable.RowStartIndex;
            int            rows               = xmlTable.Rows;
            int            objectCount        = objects.Count;
            Dictionary <int, XMLObject> cells = xmlTable.CellDic;
            Object    obj;
            Object    reuslut;
            XMLObject xmlObject;
            int       objectRowX = objectCount - rows;
            int       cellTotal  = xmlTable.CellTotal;

            IRow  row;
            IRow  rowModel = sheet.GetRow(rowStart);
            ICell cell;

            if (objectRowX > 0)
            {
                sheet.ShiftRows(rowStart + 1, sheet.LastRowNum, objectRowX);
                for (int a = 0; a < objectRowX; a++)
                {
                    row = sheet.CreateRow(rowStart + 1 + a);
                    ExcelWrite.CopyRow(rowModel, row);
                    for (int b = 0; b < cellTotal; b++)
                    {
                        cell = row.GetCell(b);
                        ICell cellModel = rowModel.GetCell(b);
                        if (cellModel != null)
                        {
                            cell.CellStyle = cellModel.CellStyle;
                        }
                    }
                }
            }
            for (int a = 0; a < objectCount; a++)
            {
                row = sheet.GetRow(a + rowStart);
                obj = objects[a];
                //循环行数据
                foreach (int b in cells.Keys)
                {
                    cell      = row.GetCell(b);
                    xmlObject = cells[b];
                    reuslut   = XMLRead.GetObjectMethodResult(xmlObject, obj);
                    cell.SetCellValue(reuslut.ToString());
                }
            }
            //检查是否组编辑
            IList <XMLGroup> xmlGroups = xmlTable.XmlGroups;
            int rs;

            if (xmlGroups != null)
            {
                foreach (XMLGroup xmlGroup in xmlGroups)
                {
                    Dictionary <String, int> symbolDic = xmlGroup.GroupDic;
                    String symbol = xmlGroup.Result;
                    for (int a = 0; a < objectCount; a++)
                    {
                        obj     = objects[a];
                        row     = sheet.GetRow(a + rowStart);
                        reuslut = XMLRead.GetObjectMethodResult(xmlGroup.XmlObject, obj);
                        if (symbolDic.TryGetValue(reuslut.ToString(), out rs))
                        {
                            cell = row.GetCell(rs);
                            cell.SetCellValue(symbol);
                        }
                        else
                        {
                            errors.Add("xml配置中:" + reuslut.ToString() + "没有这个数据的分组");
                        }
                    }
                }
            }
        }