You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.2 KiB
57 lines
2.2 KiB
using KGIS.Framework.Utils; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using Aspose.Cells; |
|
using KGIS.Framework.Platform; |
|
|
|
namespace Kingo.Plugin.DataDictionary.Helper |
|
{ |
|
public class ExportOwnerUnitCode |
|
{ |
|
public string OutPath { get; set; } |
|
public void Export(bool isBL = false) |
|
{ |
|
if (string.IsNullOrWhiteSpace(OutPath)) |
|
return; |
|
var sourcesfile = SysAppPath.GetCurrentAppPath() + @"工作空间\模板\字典模板\权属单位代码样式表.xlsx"; |
|
if (System.IO.File.Exists(sourcesfile)) |
|
{ |
|
#region 写入权属字典数据 |
|
Workbook workbook = new Workbook(sourcesfile); |
|
workbook.CalculateFormula(true); |
|
Worksheet sheet = workbook.Worksheets[0]; |
|
//获取权属字典 |
|
List<DataDicTionary> dicList = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); |
|
//List<DataDicTionary> dicList = Platform.Instance.DicHelper.GetNoGroupDic2(DicTypeEnum.QSDM, null, true, isBL, '0'); |
|
if (dicList == null) |
|
{ return; } |
|
var pandinglist = dicList.Where(x => x.CODE.Length == 12).ToList(); |
|
for (var i = 0; i < pandinglist.Count(); i++) |
|
{ |
|
pandinglist[i].CODE = pandinglist[i].CODE + "0000000"; |
|
} |
|
WriteExcel(sheet, dicList); |
|
workbook.Save(OutPath); |
|
#endregion |
|
} |
|
} |
|
private void WriteExcel(Worksheet sheet, List<DataDicTionary> dicList) |
|
{ |
|
if (dicList == null) |
|
return; |
|
var list = dicList.OrderBy(x => x.ID).ToList(); |
|
for (int i = 0; i < list.Count; i++) |
|
{ |
|
Cell cell = sheet.Cells[i + 1, 0]; |
|
if (list[i].CODE != "" && list[i].NAME != "") |
|
{ |
|
cell.PutValue(list[i].CODE); |
|
cell = sheet.Cells[i + 1, 1]; |
|
cell.PutValue(list[i].NAME); |
|
} |
|
if (dicList[i].SubDic != null) |
|
WriteExcel(sheet, dicList[i].SubDic); |
|
} |
|
} |
|
} |
|
}
|
|
|