如何格式化显示前导零

时间:2016-09-30 11:14:29

标签: reporting-services ssrs-2008 reporting ssrs-2008-r2

我试图以这种格式显示持续时间:05:02:09这是小时,分钟和秒。

目前我可以在没有此格式的前导零的情况下显示它:5:02:09

=IIF(
 Fields!DataValue.Value < 0, 0,
  Floor(Fields!DataValue.Value / 3600) &":"&Format(
    DateAdd("s",IIF(Fields!DataValue.Value < 0, 0, Fields!DataValue.Value),"00:00"),
    "mm:ss"
  )
)

当小时小于10时,如何添加前导零?

enter image description here

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,我之前尝试过,但失败了。奇怪的是,这次它起作用了。

public void ProcessRequest(HttpContext context)
    {
 HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("content-                   disposition", "attachment;filename=john.pdf");
                                                                              HttpContext.Current.Response.Cache.SetCacheability                                 (HttpCacheability.NoCache);
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

            string imagepath = context.Server.MapPath(@"~/img/logo3.png");
            Document Doc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
            HTMLWorker htmlparser = new HTMLWorker(Doc);
            PdfWriter pdfwriter = PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream);
            Doc.Open();
            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagepath);
            image.ScalePercent(106f, 90f);
            Doc.Add(image);
            AddPDf(pdfwriter, Doc);
            OnEndPage(pdfwriter, Doc);
            Doc.Close();
             HttpContext.Current.Response.End();
            }

 public void AddPDf(PdfWriter writer, Document document)
 {
 PdfPTable table = new PdfPTable(3);
 table.TotalWidth = 400f;
//fix the absolute width of the table
table.LockedWidth = true;
//relative col widths in proportions - 1/3 and 2/3
float[] widths = new float[] { 2f, 4f, 6f };
table.SetWidths(widths);
table.HorizontalAlignment = 0;
//leave a gap before and after the table
 table.SpacingBefore = 20f;
  table.SpacingAfter = 30f;
 PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
 cell.Colspan = 3;
 cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
 table.AddCell(cell);
 table.AddCell("Col 1 Row 1");
  table.AddCell("Col 2 Row 1");
  table.AddCell("Col 3 Row 1");
  table.AddCell("Col 1 Row 2");
  table.AddCell("Col 2 Row 2");
  table.AddCell("Col 3 Row 2");
 document.Open();
 document.Add(table);
    }
    public void OnEndPage(PdfWriter writer, Document document)
    {


        var content = writer.DirectContent;
        var pageBorderRect = new Rectangle(document.PageSize);

        pageBorderRect.Left += document.LeftMargin;
        pageBorderRect.Right -= document.RightMargin;
        pageBorderRect.Top -= document.TopMargin;
        pageBorderRect.Bottom += document.BottomMargin;

        content.SetColorStroke(BaseColor.BLACK);
        content.Rectangle(pageBorderRect.Left, pageBorderRect.Bottom, pageBorderRect.Width, pageBorderRect.Height);
        content.Stroke();
    }
    private static void addCell(PdfPTable table, string text, int rowspan)
    {
        BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
        iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 6, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);

        PdfPCell cell = new PdfPCell(new Phrase(text, times));
        cell.Rowspan = rowspan;
        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
        cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
        table.AddCell(cell);
    }