public class ZhCommon
{
/// <summary>
/// 根据导入配置文件生成标题数据(含objectid)
/// </summary>
/// <param name="tableName"></param>
/// <returns></returns>
public static string[] GetTitle(string tableName = "HCYSJ", string configPath = "")
{
if (string.IsNullOrEmpty(configPath))
configPath = AppDomain.CurrentDomain.BaseDirectory;
CpmVars myVar = new CpmVars(tableName, configPath);
List<string> ls = new List<string>();
//ls.Add("OID");
for (int i = 0; i < myVar.Cols.Count; i++)
{
ls.Add(myVar.Cols[i].Prompt);
}
return ls.ToArray();
}
/// <summary>
///
/// </summary>
/// <param name="tableName"></param>
/// <param name="configPath"></param>
/// <returns></returns>
public static string GenSelect(string tableName, string configPath = "")
{
if (string.IsNullOrEmpty(configPath))
configPath = AppDomain.CurrentDomain.BaseDirectory;
CpmVars myVar = new CpmVars(tableName, configPath);
List<string> ls = new List<string>(); //ls.Add("OID");
for (int i = 0; i < myVar.Cols.Count; i++)
ls.Add(myVar.Cols[i].FieldName);
return string.Format("select {0} from {1} ", string.Join(",", ls.ToArray()), tableName);
}
private void exsample()
{
MyCommon.WriteLog(ZhCommon.GenSelect("ZDMX"));
string[] title = ZhCommon.GetTitle("ZDMX");
List<string> ls = new List<string>();
foreach (var item in title)
{
ls.Add(string.Format("\"{0}\"", item));
}
MyCommon.WriteLog(string.Join(",", ls.ToArray()));
}
}
private void Test(){
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true;
Excel.Workbook wb = excelApp.Workbooks.Add();
Excel.Worksheet sht = wb.Worksheets.Add();
string shtName = "xxx";
sht.Name = shtName;
MyCommon.FillDtToWorksheet(sht, dt);
string[] title = { "序号", "日期"};
EUtil.FillArrayToWorksheet(sht, EUtil.StringArrayToMatrix(title), "A1");
sht.Cells.Select();
sht.Cells.EntireColumn.AutoFit();
//Excel.Range rng = sht.Columns["G:G"];
//rng.ColumnWidth = 38;
//excelApp.ActiveWindow.ScrollColumn = 1;
//rng = sht.Cells[1, 1];
//rng.Select();
//string fileName = string.Format("FILES/{0}_{1}.xlsx",wddm,yf);
wb.SaveAs(Filename: fileName);
wb.Close();
excelApp.Quit();
}