Excel.Application app = Globals.ThisAddIn.Application;
Excel.Worksheet sht = app.ActiveSheet as Excel.Worksheet;
Excel.Range rng = sht.UsedRange;
object[,] objs = rng.Value2;
string statementSeparator = "", ele1 = "", ele2 = "", ele3 = "";
string pre = "t.";
List<string> ls = new List<string>();
List<string> lsTitle = new List<string>();
for (int i = 2; i <= objs.GetUpperBound(0); i++)
{
string[] obj = getStrArr(objs, i);
statementSeparator = 2 == i ? "" : ",";
ele1 = obj[4 - 1]; //属性
ele2 = obj[3 - 1]; //属性名称
ele3 = string.Format("{0}{1} {2}", obj[8 - 1], MyCommon.LetterToInt(obj[8 - 1])
, obj[9 - 1].Replace("\"", "'") + " " + obj[10 - 1].Replace("\"", "'"));
ls.Add(string.Format("\t{0}{1}{2} -- [{3}] {4}"
, statementSeparator, pre
, ele1, ele2, ele3)
);
lsTitle.Add(string.Format("\"{0}\"", ele2));
}
MyCommon.WriteLog(string.Format("string[] title = {{{0}}}"
, string.Join(","
, lsTitle.ToArray()
)
));
MyCommon.WriteLog(
msg: string.Join(Environment.NewLine, ls.ToArray())
, display: true);
private string[] getStrArr(object[,] objs, int row)
{
int length = objs.GetLength(1);
/*
Array arr = Array.CreateInstance(typeof(String), new int[] { length }, new int[] { 1 });
for (int i = objs.GetLowerBound(1); i <= objs.GetUpperBound(1); i++)
{
arr.SetValue( null == objs[row, i] ? "" : objs[row, i].ToString(),i);
}
return (string[])arr;
*/
string[] result = new string[length];
for (int i = objs.GetLowerBound(1); i <= objs.GetUpperBound(1); i++)
result[i - 1] = null == objs[row, i] ? "" : objs[row, i].ToString();
return result;
}
/*
c# System.String[*] System.String[]
*/
using Excel = Microsoft.Office.Interop.Excel;
using CpmBigDataImportService;