2012-04-03 4 views
0

OpenXML의 스프레드 시트 셀에서 텍스트를 옆으로 인쇄하는 방법을 알아 내려고합니다. Cell 클래스의 ExtendedProperties를 사용하여 어떻게 든 할 수 있다고 생각합니다. 여기 내가 가진거야.OpenXML SpreadsheetML 옆면 텍스트

Cell cell = GetCell(worksheetPart.Worksheet, columnName, rowIndex); 
    cell.DataType = CellValues.InlineString; 
    cell.InlineString = new InlineString() { Text = new Text(textToInsert) }; 

    //fictitious method 
    cell.ExtendedAttributes.SpinSideways(); 
    worksheetPart.Worksheet.Save() 
+0

복제를 HTTP의 : 90 90 이제

에 당신은 CellFormatsCellFormat 다음 원하는 셀의 StyleIndex에 새 인덱스가 회전 한 것을 설정하는 것이 삽입해야합니다 // 유래를 .com/questions/605966 6/answer/submit? s = 9219459d-a516-4000-9913-d6d5843fecb7? – emd

답변

3

스타일은 Excel 문서의 CellFormats 섹션에서 처리됩니다. 셀이 형식이 때 XML보고하고 s 속성이 정수로 설정되어있는 것을 볼 때 알 수 있습니다 :

<x:c r="A1" s="1" t="s" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> 
    <x:v>0</x:v> 
</x:c> 

그 속성이 CellFormats 목록에서 CellFormat 지수 인 StyleIndex을 의미하는 이 셀의 서식 지정에 해당합니다. 여기에 CellFormats의 XML 희망이 조금 명확하게하는 것입니다

<x:cellXfs count="2" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> 
    <x:xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" /> 
    <x:xf numFmtId="0" fontId="0" fillId="1" borderId="1" xfId="0" /> 
</x:cellXfs> 

을 우리가 CellFormats 요소 인 x:cellXfs 요소가 위의 XML에서 그것은 x:xf 또는 CellFormat 요소의 두 아이가 있습니다. 우리는 우리가 원하는 우리가 의미 CellFormats 요소 아래 첫 번째 인덱스 (또는 두 번째 요소)를 원하는 StyleIndex 속성에서 알이 CellFormat : 이제 셀의 텍스트를하기 위해 회전

<x:xf numFmtId="0" fontId="0" fillId="1" borderId="1" xfId="0" /> 

당신이

해야합니다 CellFormat을 통해 제어하십시오. 다음은 90도 회전으로 CellFormat를 생성하기 위해 사용해야합니다 코드입니다 : 다른 각도로 회전 할 텍스트를 원하는 경우

public CellFormat GenerateCellFormat() 
{ 
    CellFormat cellFormat1 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyAlignment = true }; 
    Alignment alignment1 = new Alignment(){ TextRotation = (UInt32Value)90U }; 

    cellFormat1.Append(alignment1); 
    return cellFormat1; 
} 

다음 당신이에서 원하는 각도로 90U 교체는 -

Cell cell = GetCell(worksheetPart.Worksheet, columnName, rowIndex); 
cell.StyleIndex = InsertCellFormat(workbookPart, GenerateCellFormat()); 

// Helper method to insert the cell format in the CellFormats 
public static uint InsertCellFormat(WorkbookPart workbookPart, CellFormat cellFormat) 
{ 
    CellFormats cellFormats = workbookPart.WorkbookStylesPart.Stylesheet.Elements<CellFormats>().First(); 
    cellFormats.Append(cellFormat); 
    return (uint)cellFormats.Count++; 
} 
+0

나는 그 요소를 말하고있다. 시퀀스는 요소가 없다. 생각[email protected] – Kulingar

+0

을 그것은 CellFormats 요소가 존재하지 않는 것을 의미하고 당신이 그것을 추가하거나 이미 정의 된 CellFormat이있는 Excel 파일을 사용해야합니다. – amurra

+0

어떻게 추가합니까? :( – Kulingar

1

먼저 스타일 시트를 만든 다음 셀에 적용해야합니다.

몇 가지 중요한 snippits :

cell.StyleIndex=INDEXOFYOURSTYLE;

자원 그리고

Alignment align = new Alignment(); 
align.TextRotation.Value = 90; 
CellFormat format = CellFormat(){Alignment= align}; 

을 셀에 적용 :

스타일링을 포함시킬 필요가 스타일 시트를 들어

스프레드 시트 : http://blogs.msdn.com/b/chrisquon/archive/2009/11/30/stylizing-your-excel-worksheets-with-open-xml-2-0.aspx

MSDN- 정렬 : 세포 http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.alignment.aspx