2013-04-26 3 views
2

여기 내 문제는 짧습니다. 나는 그것이 우리의 porpus에 적합한 지 아닌지 알아 내기 위해 OfficeWriter의 데모 버전을 사용하고 있습니다. 특히 4 개의 DataTable의 X-Y 열을 나타내는 8 개의 자리 표시 자로 구성된 Excel 템플릿과 Excel에서 열을 다시 나타내는 열 쌍을 참조하여 4 개의 시리즈를 추가하는 Excel 분산 형 차트를 준비했습니다. enter image description here 내 코드에서이 템플릿을 목록의 항목에 따라 여러 번 복사하고 항목 이름 뒤에 복사 한 시트의 이름을 지정합니다 (이 경우 wb.CopySheet (...) 메서드 사용). 여기서 주요 문제는 "xlt.process()"메서드를 호출 할 때 Y- 범위 데이터 마커를 올바른 시트 이름으로 올바르게 업데이트하지만 X- 범위 데이터 마커를 업데이트하지 않는 것입니다. enter image description here 누군가 내게 손을 줄 수 있습니까?DataTable을 Excel 템플릿 시트에 바인딩 한 후 DataTable 자리 표시 자 위에 Excel 분산 형 차트를 작성하려면 어떻게해야합니까?

+0

사용중인 코드를 게시 할 수 있습니까? –

+0

Excel 템플릿을 사용하여 차트 생성을위한 OfficeWriter 자습서를 체크 아웃 할 수도 있습니다. 또한 샘플 코드도 있습니다. 이것은 http://wiki.softartisans.com/display/EW8/Using+Charts+with+ExcelTemplate –

답변

2

이 버그가 나타납니다. OfficeWriter가 차트의 값을 읽을 때 .ScatterValues ​​속성이 올바른 범위 값 (예 : = Sheet2! $ R $ 2 : $ R $ 2)으로 설정되어 CopySheet가 실패하게됩니다. 이 버그를 수정하기 위해 개발 용 버그를 제출했습니다. 내가 SoftArtisans 작동, OfficeWriter의 업체 :

string templatePath = "input.xlsx"; 

/* Open the template workbook */ 
ExcelApplication xla = new ExcelApplication(); 
var wb = xla.Open(templatePath); 

/* Select the template worksheet to copy */ 
var origWS = wb.Worksheets["Sheet1"]; 

/* Make a copy of the worksheet with the given name */ 
var wsName = "Sheet2"; 
wb.Worksheets.CopySheet(origWS, 1, wsName); 

/* For the new worksheet, update the ScatterValues to point to this sheet */ 
var newWS = wb.Worksheets[wsName]; 
newWS.Charts[0].SeriesCollection[0].ScatterValues = "=" + wsName + "!$B$27"; 

/* Create an instance of ExcelTemplate */ 
ExcelTemplate xlt = new ExcelTemplate(); 

/* Open the workbook from the ExcelApplication object above */ 
xlt.Open(xla, wb); 

면책 조항 :

당신이 .ScatterValues ​​위의 코드에서 ( http://wiki.softartisans.com/display/EW8/Series.ScatterValues 참조) 속성을 설정할 수 있습니다,이 문제를 해결하려면.

+0

정말 고마워, 나는 실제로 그것이 버그라고 느끼고 있었지만 대답과 해결 방법을 제안 해 주셔서 감사합니다. 당신은 곧 그것을 고쳐 줄 것이라고 생각합니까? – user2324645

+0

내 이전 의견 수정 :이 문제는 개발팀에 전달되어 처리되었습니다. 그들이 일정을 정할 때 결정되지 않았습니다. 원하는 경우 SoftArtisans (http://www.softartisans.com/contact-softartisans)에 직접 문의 할 수 있으며 팀에서이 문제를 직접 해결하도록 도울 수 있습니다. 이 게시물을 언급하면 ​​올바르게 라우팅됩니다. –

1

나는 OfficeWriter 사랑 (면책 조항 : 나는 OfficeWriter에 개발자입니다) 나는 설정에 대한 빠른 샘플 수 있었다 달성이 :

using System; using System.Data; using SoftArtisans.OfficeWriter.ExcelWriter; 

namespace ExcelTemplateScatterChart { 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      /* Create an instance of ExcelTemplate */ 
      ExcelTemplate xlt = new ExcelTemplate(); 

      /* Open the template workbook */ 
      string templatePath = "input.xlsx"; 
      xlt.Open(templatePath); 

      /* Query the database for report data */ 
      DataTable dt1 = GetTable1(); 
      DataTable dt2 = GetTable2(); 

      /* Pass the DataTable to ExcelTemplate */ 
      xlt.BindData(dt1, "DataTable1", xlt.CreateDataBindingProperties()); 
      xlt.BindData(dt2, "DataTable2", xlt.CreateDataBindingProperties()); 

      /* Call the process() method to populate the 
      * template with the data source values 
      */ 
      xlt.Process(); 

      /* Save the report by streaming it 
      * to the client's browser */ 
      xlt.Save("output.xlsx"); 
     } 

     /// <summary> 
     /// This example method generates a DataTable. 
     /// </summary> 
     static DataTable GetTable1() 
     { 
      // 
      // Here we create a DataTable with four columns. 
      // 
      DataTable table = new DataTable(); 
      table.Columns.Add("x", typeof(int)); 
      table.Columns.Add("y", typeof(int)); 

      // 
      // Here we add three DataRows. 
      // 
      table.Rows.Add(1, 10); 
      table.Rows.Add(2, 20); 
      table.Rows.Add(3, 30); 
      return table; 
     } 

     /// <summary> 
     /// This example method generates a DataTable. 
     /// </summary> 
     static DataTable GetTable2() 
     { 
      // 
      // Here we create a DataTable with four columns. 
      // 
      DataTable table = new DataTable(); 
      table.Columns.Add("x", typeof(int)); 
      table.Columns.Add("y", typeof(int)); 

      // 
      // Here we add three DataRows. 
      // 
      table.Rows.Add(1, 30); 
      table.Rows.Add(2, 20); 
      table.Rows.Add(3, 10); 
      return table; 
     } 
    } } 

내가 설정 내 템플릿 : 다음 코드를 사용하여

같은 :

enter image description here

그리고는 datamarkers/장소 홀더를 가리 키도록 차트를 구성 같은

enter image description here

결과 출력은 내 코드를 실행 한 후 다음 무엇을 :

enter image description here

+0

에서 찾을 수 있습니다. 제 질문에 충분히 명확하지 않은 경우 사과드립니다. 설득력있는 설명을 할 시간이 없었습니다. 스크린 샷. 나는 나의 질문을 더 자세히 묘사했다. – user2324645

관련 문제