Dictionary<string,string> items = new Dictionary<string,string>();
IEnumerable<string> textvalues = from c in......//using linQ to query
string s = textvalues[items["book"]];
이 경우 textvalues 배열은 문자열 값을 반환 할 정수 값을 허용합니다. 항목 번호를 가져올 수있는 방법은 "항목"에 5 개의 항목 이름이 있고 "책"이 첫 번째 위치에 있고 그 다음에는 0을 가져야합니다. . 텍스트 값 [items [0]]은 사전 항목의 주문 번호를 얻는 방법이 있습니까?
좋아요. Excel을 읽으려고 OpenXML 2.0을 사용하려고했습니다. 여기 요점은 내가 지정할 수있는 방법이 없습니다. 필드 이름과 가치를 얻을. 그래서 워크 시트의 첫 번째 행을 반복하려고했는데 사전 fieldItems에 값을 추가합니다. 그래서 fieldItems [ "Status"]라고 말하면 열 값을 기반으로 셀 값을 검색합니다. column header name.ok 여기에 대한 코드가 있습니다.
Dictionary<string, int> headers = new Dictionary<string, int>();
IEnumerable<string> ColumnHeaders = from cell in (from row in worksheet.Descendants<Row>()
where row.RowIndex == 1
select row).First().Descendants<Cell>()
where cell.CellValue != null
select
(cell.DataType != null
&& cell.DataType.HasValue
&& cell.DataType == CellValues.SharedString
? sharedString.ChildElements[
int.Parse(cell.CellValue.InnerText)].InnerText
: cell.CellValue.InnerText);
int i=0;
Parallel.ForEach(ColumnHeaders, x => { headers.Add(x,i++); });
order.Number = textValues[headers["Number"]];
IEnumerable에 인덱스 접근자가 있습니까? 대신 IList 을 사용해야 할 수도 있습니다. –
IEnumerable에는 인덱스 접근자가 없습니다. –
TheFogger
아직 실제로 textvalues가 무엇인지는 분명하지 않지만 * 당신을 도울 수있는 방법으로 내 대답을 편집했습니다 ... –