Пример #1
0
        // Write
        internal static void WritePageSetupToWriter(CustomOpenXmlWriter<OpenXmlPackaging.WorksheetPart> writer, PageSetup pageSetup)
        {
            if (pageSetup.HasValue())
            {
                writer.WriteOpenXmlElement(new OpenXmlSpreadsheet.PageSetup());

                if (pageSetup.BlackAndWhite) writer.WriteAttribute("blackAndWhite", pageSetup.BlackAndWhite);
                if (pageSetup.Copies > 1) writer.WriteAttribute("copies", pageSetup.Copies);
                if (pageSetup.Draft) writer.WriteAttribute("draft", pageSetup.Draft);
                if (pageSetup.FirstPageNumber > 1) writer.WriteAttribute("firstPageNumber", pageSetup.FirstPageNumber);
                if (pageSetup.FitToHeight > -1) writer.WriteAttribute("fitToHeight", pageSetup.FitToHeight);
                if (pageSetup.FitToWidth > -1) writer.WriteAttribute("fitToWidth", pageSetup.FitToWidth);
                if (pageSetup.HorizontalDpi != 600) writer.WriteAttribute("horizontalDpi", pageSetup.HorizontalDpi);
                if (pageSetup.VerticalDpi != 600) writer.WriteAttribute("verticalDpi", pageSetup.VerticalDpi);
                if (pageSetup.Orientation != WorksheetOrientation.Portrait) writer.WriteAttribute("orientation", Helpers.ToCamelCase(pageSetup.Orientation.ToString()));
                if (pageSetup.PaperSize != 9) writer.WriteAttribute("paperSize", pageSetup.PaperSize);
                if (pageSetup.RelationshipId != "") writer.WriteAttribute("id", pageSetup.RelationshipId, "r");
                if (pageSetup.Scale != 400) writer.WriteAttribute("scale", pageSetup.Scale);
                if (pageSetup.UseFirstPageNumber) writer.WriteAttribute("useFirstPageNumber", pageSetup.UseFirstPageNumber);
                if (pageSetup.UsePrinterDefaults) writer.WriteAttribute("usePrinterDefaults", pageSetup.UsePrinterDefaults);

                writer.WriteEndElement();   // PageSetup
            }
        }
Пример #2
0
 /***********************************
  * INTERNAL METHODS
  ************************************/
 internal PageSetup Clone(Worksheet worksheet)
 {
     PageSetup newPageSetup = new PageSetup(worksheet,
         BlackAndWhite, Copies, Draft, FirstPageNumber, FitToHeight, FitToWidth, HorizontalDpi, VerticalDpi, RelationshipId, Orientation,
         PaperSize, Scale, UseFirstPageNumber, UsePrinterDefaults);
     return newPageSetup;
 }
Пример #3
0
        /***********************************
         * DAL METHODS
         ************************************/
        // Read
        internal static PageSetup ReadPageSetupFromReader(CustomOpenXmlReader reader, Worksheet worksheet)
        {
            PageSetup pageSetup = new PageSetup(worksheet);

            foreach (CustomOpenXmlAttribute attribute in reader.Attributes)
            {
                switch (attribute.LocalName)
                {
                    case "blackAndWhite":
                        pageSetup.BlackAndWhite = attribute.GetBoolValue();
                        break;
                    case "copies":
                        pageSetup.Copies = attribute.GetIntValue();
                        break;
                    case "draft":
                        pageSetup.Draft = attribute.GetBoolValue();
                        break;
                    case "firstPageNumber":
                        pageSetup.FirstPageNumber = attribute.GetIntValue();
                        break;
                    case "fitToHeight":
                        pageSetup.FitToHeight = attribute.GetIntValue();
                        break;
                    case "fitToWidth":
                        pageSetup.FitToWidth = attribute.GetIntValue();
                        break;
                    case "horizontalDpi":
                        pageSetup.HorizontalDpi = attribute.GetIntValue();
                        break;
                    case "verticalDpi":
                        pageSetup.VerticalDpi = attribute.GetIntValue();
                        break;
                    case "id":
                        pageSetup.RelationshipId = attribute.Value;
                        break;
                    case "orientation":
                        switch (attribute.Value)
                        {
                            case "landscape":
                                pageSetup.Orientation = WorksheetOrientation.Landscape;
                                break;
                            case "portrait":
                                pageSetup.Orientation = WorksheetOrientation.Portrait;
                                break;
                        }
                        break;
                    case "paperSize":
                        pageSetup.PaperSize = attribute.GetIntValue();
                        break;
                    case "scale":
                        pageSetup.Scale = attribute.GetIntValue();
                        break;
                    case "useFirstPageNumber":
                        pageSetup.UseFirstPageNumber = attribute.GetBoolValue();
                        break;
                    case "usePrinterDefaults":
                        pageSetup.UsePrinterDefaults = attribute.GetBoolValue();
                        break;
                    default:
                        throw new Exception(string.Format("PageSetup attribute {0} not coded", attribute.LocalName));
                }
            }

            return pageSetup;
        }