2016-06-03 2 views
0

이 코드를 사용하여 Excel 파일을 내보내고 있습니다. 그것은 잘 작동합니다. 내 보낸 파일에 테두리를 적용하는 방법은 무엇입니까?

public void WriteHtmlTable<T>(IEnumerable<T> data, TextWriter output) 
{ 

    using (StringWriter sw = new StringWriter()) 
    { 
     using (HtmlTextWriter htw = new HtmlTextWriter(sw)) 
     { 
      Table table = new Table(); 
      TableRow row = new TableRow(); 
      PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T)); 
      foreach (PropertyDescriptor prop in props) 
      { 
       TableCell cell = new TableCell(); 
       cell.Text = prop.Name; 
       row.Cells.Add(cell); 
      } 

      table.Rows.Add(row); 


      foreach (T item in data) 
      { 
       row = new TableRow(); 
       foreach (PropertyDescriptor prop in props) 
       { 
        TableCell cell = new TableCell(); 
        cell.Text = prop.Converter.ConvertToString(prop.GetValue(item)); 

        row.Cells.Add(cell); 

       } 

       table.Rows.Add(row); 
      } 

      table.RenderControl(htw); 
      output.Write(sw.ToString()); 
     } 
    } 

} 

나에게 내가 원하는 이 출력 enter image description here

하지만 출력을 제공 모든 행과 columns.what 변화가 내 코드에서해야 할이 enter image description here

내가 경계를 원하는 것입니다 ?? 미리 감사드립니다 ...

+0

을 Excel을 실제 Excel 파일을하지 쓰는 HTML을 출력하고 호출하여. 또는 정말로 필요한 경우 적절한 CSS를 적용하여 그렇게 할 수 있습니다. – CodeCaster

+0

html을 출력하고 jquery에서 Excel 파일을 호출하고 있습니다. – akash

+0

예. 좋습니다. HTML은 Excel이 아닙니다. – CodeCaster

답변

0

이 정보는 도움이 될 수 있습니다. 나는 코드를 테스트하지 않은하지만 당신은

//Add Borders for All Cells 
      sheet.Range["A1:E9"].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin; 
      sheet.Range["A1:E9"].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin; 
      sheet.Range["A1:E9"].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin; 
      sheet.Range["A1:E9"].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin; 

주처럼 뭔가를 할 수 있지만 : 참조 https://janewdaisy.wordpress.com/2011/12/05/c-add-borders-for-cells/

관련 문제