示例#1
0
        private static LevelObject Match(ISheet sheet, WbsInfo parentInfo, int rowIndex, int colIndex)
        {
            LevelObject result = AllObjects.FirstOrDefault(m => m.StrartRowIndex <= rowIndex && m.EndRowIndex >= rowIndex && m.ColIndex == colIndex);

            if (result == null)
            {
                ICell cell = sheet.GetRow(rowIndex).GetCell(colIndex);
                if (cell == null || String.IsNullOrEmpty(cell.StringCellValue))
                {
                    return(null);
                }

                WbsInfo info = new WbsInfo();
                info.WbsName = cell.StringCellValue;
                if (parentInfo != null)
                {
                    parentInfo.WbsInfos.Add(info);
                }
                else
                {
                    wbsRootInfos.Add(info);
                }
                int rangeIndex         = 0;
                CellRangeAddress range = GetMergedRegionIndex(sheet, rowIndex, colIndex, out rangeIndex);

                LevelObject tmp = new LevelObject();
                tmp.ColIndex       = colIndex;
                tmp.StrartRowIndex = rowIndex;
                if (range != null)
                {
                    tmp.EndRowIndex = range.LastRow;
                }
                else
                {
                    tmp.EndRowIndex = rowIndex;
                }
                tmp.WbsInfo = info;
                AllObjects.Add(tmp);
                result = tmp;
            }
            return(result);
        }
示例#2
0
        private static List <WbsInfo> GetWbsInfos(ISheet sheet)
        {
            //工资项标题行序号
            int rowIndex = -1;
            //部门名称开始列序号
            int        colIndex      = -1;
            List <int> removeColumns = new List <int>();
            IRow       titleRow      = null;

            for (int j = 0; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数
            {
                IRow row = sheet.GetRow(j);             //读取当前行数据
                if (row != null)
                {
                    ICell cell = row.GetCell(0);  //当前表格
                    if (cell != null)
                    {
                        String strCell = cell.ToString();   //获取表格中的数据并转换为字符串类型
                        if (strCell.Equals("单位工程"))
                        {
                            titleRow = row;
                            colIndex = cell.ColumnIndex;
                            break;
                        }
                    }
                }
            }
            if (titleRow != null)
            {
                rowIndex = titleRow.RowNum;//获取占位符所在行
                int         currentRowIndex = rowIndex + 1;
                int         rangeIndex      = 0;
                LevelObject currentObject   = null;
                wbsRootInfos.Clear();
                AllObjects.Clear();
                List <WbsInfo> RootInfo   = new List <WbsInfo>();
                WbsInfo        parentInfo = null;
                for (int i = currentRowIndex; i <= sheet.LastRowNum; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (j == 0)
                        {
                            parentInfo = null;
                        }
                        LevelObject tmp = Match(sheet, parentInfo, i, j);
                        if (tmp != null)
                        {
                            currentObject = tmp;
                            parentInfo    = tmp.WbsInfo;
                        }
                    }
                    //图纸号等信息
                    String startZNo = sheet.GetRow(i).GetCell(7).ToString();
                    String endZNo   = sheet.GetRow(i).GetCell(8).ToString();
                    String drawNo   = sheet.GetRow(i).GetCell(9).ToString();
                    currentObject.WbsInfo.DrawNo  = drawNo;
                    currentObject.WbsInfo.StartNo = startZNo;
                    currentObject.WbsInfo.EndNo   = endZNo;
                    String itemCode = sheet.GetRow(i).GetCell(10).ToString();
                    String itemName = sheet.GetRow(i).GetCell(11).ToString();
                    if (!String.IsNullOrEmpty(itemCode) || !String.IsNullOrEmpty(itemName))
                    {
                        BoiInfo boiInfo = new BoiInfo();
                        boiInfo.BoiCode = itemCode;
                        boiInfo.BoiName = itemName;
                        boiInfo.Qty     = Convert.ToDecimal(sheet.GetRow(i).GetCell(13).NumericCellValue);
                        currentObject.WbsInfo.Details.Add(boiInfo);
                    }
                }
                int codeIndex = 1;
                wbsRootInfos.ForEach(m => {
                    m.WbsCode = String.Format("{0:D2}", codeIndex);
                    DGLines(m);
                    codeIndex++;
                });
            }
            return(wbsRootInfos);
        }
示例#3
0
        private static List <WBSline> ImportTotalSheetContent(ISheet sheet)
        {
            //工资项标题行序号
            int rowIndex = -1;
            //部门名称开始列序号
            int        colIndex      = -1;
            List <int> removeColumns = new List <int>();
            IRow       titleRow      = null;

            for (int j = 0; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数
            {
                IRow row = sheet.GetRow(j);             //读取当前行数据
                if (row != null)
                {
                    ICell cell = row.GetCell(0);  //当前表格
                    if (cell != null)
                    {
                        String strCell = cell.ToString();   //获取表格中的数据并转换为字符串类型
                        if (strCell.Equals("单位工程"))
                        {
                            titleRow = row;
                            colIndex = cell.ColumnIndex;
                            break;
                        }
                    }
                }
            }
            if (titleRow != null)
            {
                rowIndex = titleRow.RowNum;//获取占位符所在行
                int         currentRowIndex = rowIndex + 1;
                int         rangeIndex      = 0;
                LevelObject currentObject   = null;
                wbsRootInfos.Clear();
                AllObjects.Clear();
                List <WbsInfo> RootInfo   = new List <WbsInfo>();
                WbsInfo        parentInfo = null;
                for (int i = currentRowIndex; i <= sheet.LastRowNum; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (j == 0)
                        {
                            parentInfo = null;
                        }
                        LevelObject tmp = Match(sheet, parentInfo, i, j);
                        if (tmp != null)
                        {
                            currentObject = tmp;
                            parentInfo    = tmp.WbsInfo;
                        }
                    }
                }
            }
            int            codeIndex = 1;
            List <WBSline> lines     = new List <WBSline>();

            wbsRootInfos.ForEach(m => {
                WBSline line     = new WBSline();
                line.WbsSysCode  = String.Format("{0:D2}", codeIndex);
                line.WbsLineName = m.WbsName;
                m.WbsCode        = line.WbsSysCode;
                lines.Add(line);
                DGLines(lines, m);
                codeIndex++;
            });
            return(lines);
        }