2017-11-21 13 views
1

이것은 문자열 이스케이프의 간단한 문제인 것처럼 보입니다. 그러나 올바른 형식을 찾을 수없고 찾을 수 없습니다. Excel 바닥 글에서 필드를 사용하는 예가 포함 된 문서OpenXML을 사용하여 스프레드 시트 생성 및 사용자 정의 바닥 글에서 [페이지] & [페이지] 가져 오기

문제의 특성은 다음과 같습니다 생성하고 스프레드 시트를 열고 파일로 이동 한 후

using (ExcelPackage pckExport = new ExcelPackage()) 
      { 
       ExcelWorksheet xlSheet = pckExport.Workbook.Worksheets.Add(SystemEnum.GetEnumDescription(typeof(SystemEnum.Reports), SystemEnum.Reports.GroomingCalendarReport.GetHashCode())); 
       try 
       { 
        int miRow = 1; 
        string pageHeader = "Calendar Report"; 
        xlSheet.Cells.Style.Font.Size = 9; 
        xlSheet.Cells.Style.Font.Name = "Times New Roman"; 
        DateTime reportDate = Convert.ToDateTime(rptDate); 
        ////set the report header 
        xlSheet.HeaderFooter.OddHeader.CenteredText = "&\"Times New Roman,Bold\"&12" + "\n" + pageHeader + "\n" + " &11for&12 " + reportDate.Date.DayOfWeek.ToString() + " , " + reportDate + 
                    "\n" + Location; 
        xlSheet.HeaderFooter.OddFooter.LeftAlignedText = "&[Page] of &[Pages]"; 
        xlSheet.HeaderFooter.OddFooter.RightAlignedText = DateTime.Now.ToShortDateString(); 

:

여기
xlSheet.HeaderFooter.OddFooter.LeftAlignedText = "&[Page] of &[Pages]"; 

추가 컨텍스트에 대한 워크 시트를 생성하는 코드의 더 큰 조각이다 \ Print 메뉴를 사용하면 바닥 글이 올바르게 표시되지 않습니다.

다음은 바닥 글의 화면 그래 브입니다. Page of Pages

내가 페이지 설정으로 이동하여 대화 상자 바닥 글 사용자 정의 선택하면 & [페이지]의 [페이지] &으로 올바른 형식 바닥 글의 정보를 보여줍니다 내가 좋아를 클릭 할 경우 대화 상자가 다음 쇼를 인쇄 미리보기를 닫습니다 바닥 글 올바르게 Custom Footer Dialog Box

내가 명시 적 문자열을 사용하고 & [페이지]하지만 미리보기의 페이지의 모두 반환 페이지]]와 정확하게 사용하여 시도했다 : 여기

사용자 정의 바닥 글 대화 상자의 화면 잡아입니다 사용자 지정 바닥 글 상자에서 보낸 텍스트

나는 이것에 대한 도움을 찾기 위해 내 아이디어를 다 써 버렸다.

아무도 도와 줄 수 있습니까?

감사합니다, 당신은 ExcelHeaderFooter 개체 보면

답변

0

당신이 당신이 원하는 것을 달성 할 수 있도록 매우 도움이 const 's의 전체 무리가 표시됩니다

여기
var wb = pck.Workbook; 
var ws = wb.Worksheets.Add("Sheet1"); 
ws.Cells[1, 1].Value = "Test"; 

var footer = $"Page {ExcelHeaderFooter.PageNumber} of {ExcelHeaderFooter.NumberOfPages}"; 
ws.HeaderFooter.EvenFooter.CenteredText = footer; 
ws.HeaderFooter.OddFooter.CenteredText = footer; 

가로 표시됩니다 것입니다 버전 4.1의 버전 :

#region Static Properties 
/// <summary> 
/// The code for "current page #" 
/// </summary> 
public const string PageNumber = @"&P"; 
/// <summary> 
/// The code for "total pages" 
/// </summary> 
public const string NumberOfPages = @"&N"; 
/// <summary> 
/// The code for "text font color" 
/// RGB Color is specified as RRGGBB 
/// Theme Color is specified as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade value, NN is the tint/shade value. 
/// </summary> 
public const string FontColor = @"&K"; 
/// <summary> 
/// The code for "sheet tab name" 
/// </summary> 
public const string SheetName = @"&A"; 
/// <summary> 
/// The code for "this workbook's file path" 
/// </summary> 
public const string FilePath = @"&Z"; 
/// <summary> 
/// The code for "this workbook's file name" 
/// </summary> 
public const string FileName = @"&F"; 
/// <summary> 
/// The code for "date" 
/// </summary> 
public const string CurrentDate = @"&D"; 
/// <summary> 
/// The code for "time" 
/// </summary> 
public const string CurrentTime = @"&T"; 
/// <summary> 
/// The code for "picture as background" 
/// </summary> 
public const string Image = @"&G"; 
/// <summary> 
/// The code for "outline style" 
/// </summary> 
public const string OutlineStyle = @"&O"; 
/// <summary> 
/// The code for "shadow style" 
/// </summary> 
public const string ShadowStyle = @"&H"; 
#endregion 
+0

Ernie, 귀하의 조언이 자리를 잡았고 올바르게 작동하는 시트가 있습니다. 문서에 대한 링크를 제공해 주셔서 감사합니다. 나는 왜 어제 그것을 찾을 수 없었는지 전혀 모르겠다. 나는 너무 좌절했다. 어쨌든 감사합니다. – John