Click here to Skip to main content
15,903,201 members
Home / Discussions / Java
   

Java

 
AnswerRe: POI ShrinkToFit Pin
427748026-Sep-09 1:36
427748026-Sep-09 1:36 
GeneralRe: POI ShrinkToFit Pin
DaveyM6926-Sep-09 3:06
professionalDaveyM6926-Sep-09 3:06 
GeneralRe: POI ShrinkToFit Pin
427748026-Sep-09 5:21
427748026-Sep-09 5:21 
GeneralRe: POI ShrinkToFit Pin
DaveyM6926-Sep-09 6:59
professionalDaveyM6926-Sep-09 6:59 
GeneralPOI ShrinkToFit Solution Pin
DaveyM6926-Sep-09 7:37
professionalDaveyM6926-Sep-09 7:37 
GeneralRe: POI ShrinkToFit Solution Pin
427748028-Sep-09 1:43
427748028-Sep-09 1:43 
GeneralRe: POI ShrinkToFit Solution Pin
DaveyM6928-Sep-09 3:09
professionalDaveyM6928-Sep-09 3:09 
GeneralRe: POI ShrinkToFit Solution Pin
427748030-Sep-09 1:07
427748030-Sep-09 1:07 
I believe you want to use your code server side without having Excel be installed. But for those of us who want to add image to header I did the following:

// In C#
public static void SetLeftHeaderPicture(String Workbook,String Sheet,String Image)
        {
            Application excelApp = new ApplicationClass();
            excelApp.Visible = false;
            Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            string workbookPath = Workbook;
            Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);
            Sheets excelSheets = excelWorkbook.Worksheets;
            string currentSheet = Sheet;
            Worksheet excelWorksheet = (Worksheet)excelSheets.get_Item(currentSheet);
            excelWorksheet = (Worksheet)excelWorkbook.ActiveSheet;
            excelWorksheet.PageSetup.LeftHeaderPicture.Filename = Path.GetFullPath(Image);
            excelWorksheet.PageSetup.LeftHeader = "&G";
            excelWorksheet.PageSetup.LeftHeaderPicture.Height = 100;
            excelWorksheet.PageSetup.LeftHeaderPicture.Width = 150;
            excelWorkbook.Save();
        }

Just repeat the same method for the rest for example if you want to add right header then the things to change will be the method name will be SetRightHeaderPicture and the following lines would be:
// In C#
excelWorksheet.PageSetup.RightHeaderPicture.Filename = Path.GetFullPath(Image);
            excelWorksheet.PageSetup.RightHeader = "&G";
            excelWorksheet.PageSetup.RightHeaderPicture.Height = 100;
            excelWorksheet.PageSetup.RightHeaderPicture.Width = 150;


You can also add any other property you want by excelWorksheet.PageSetup.RightHeaderPicture.<"your selection"> = value

In Java it is a little different but will yield the same result.

1. Download the new Jar and HFPicture.exe from Link[^]
2. Set a Java project and paste the exe in the project directory and add a build reference to the jar
3. Code
// In Java
HSSFHeader header = sheet.getHeader();// or Footer
// Do what ever you want here but do not set the header to the place you want the image to be and make sure you write the excel file at this stage
// The last line for example in the Main method must be:
HeaderFooter.HFPicture("CH", "C:\\Excel.xls", "Sheet0", "c:\\image.jpg");
/*
1. Where CH means CenterHeader
2. Where C:\\Excel.xls is the path of the output excel
3. Where Sheet0 is the sheet
4. Where c:\\image.jpg is the image you want to set
*/


In addition to the code of setting the image in header for Java users we need:
// Add this in Main method in C# class
StreamReader objReader = new StreamReader("HFPicture.txt");
            string sLine = "";
            ArrayList arrText = new ArrayList();

            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                    arrText.Add(sLine);
            }
            objReader.Close();

            if (arrText[0].ToString() == "LH")
                SetLeftHeaderPicture(arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString());
            if (arrText[0].ToString() == "CH")
                SetCenterHeaderPicture(arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString());
            if (arrText[0].ToString() == "RH")
                SetRightHeaderPicture(arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString());
            if (arrText[0].ToString() == "LF")
                SetLeftFooterPicture(arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString());
            if (arrText[0].ToString() == "CF")
                SetCenterFooterPicture(arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString());
            if (arrText[0].ToString() == "RF")
                SetRightFooterPicture(arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString());


I hope this helps. If you develop the solution in pure NPOI and you post it here I will try to also do it in Java POI. Also refer that the changes in my previous post are also included in this build.

Regards
GeneralRe: POI ShrinkToFit Solution Pin
DaveyM6930-Sep-09 6:24
professionalDaveyM6930-Sep-09 6:24 
GeneralRe: POI ShrinkToFit Solution Pin
427748030-Sep-09 10:46
427748030-Sep-09 10:46 
GeneralRe: POI ShrinkToFit Solution Pin
DaveyM6930-Sep-09 23:18
professionalDaveyM6930-Sep-09 23:18 
GeneralRe: POI ShrinkToFit Solution Pin
42774801-Oct-09 9:43
42774801-Oct-09 9:43 
GeneralImage in Excel Header/Footer Solution Continuation Pin
42774803-Oct-09 4:13
42774803-Oct-09 4:13 
GeneralRe: Image in Excel Header/Footer Solution Continuation Pin
42774803-Oct-09 9:00
42774803-Oct-09 9:00 
Questionhow to set thread affinity in JAVA Pin
evyatar.v25-Sep-09 11:13
evyatar.v25-Sep-09 11:13 
AnswerRe: how to set thread affinity in JAVA Pin
427748025-Sep-09 19:29
427748025-Sep-09 19:29 
GeneralRe: how to set thread affinity in JAVA Pin
evyatar.v25-Sep-09 21:40
evyatar.v25-Sep-09 21:40 
GeneralRe: how to set thread affinity in JAVA Pin
427748026-Sep-09 0:05
427748026-Sep-09 0:05 
QuestionNeed help with hash table Pin
snssewell24-Sep-09 22:21
snssewell24-Sep-09 22:21 
AnswerRe: Need help with hash table Pin
427748025-Sep-09 0:39
427748025-Sep-09 0:39 
GeneralRe: Need help with hash table Pin
snssewell25-Sep-09 19:30
snssewell25-Sep-09 19:30 
QuestionRead SDF using Java Pin
jason975424-Sep-09 21:30
jason975424-Sep-09 21:30 
AnswerRe: Read SDF using Java Pin
427748025-Sep-09 0:36
427748025-Sep-09 0:36 
GeneralRe: Read SDF using Java Pin
jason975425-Sep-09 4:12
jason975425-Sep-09 4:12 
GeneralRe: Read SDF using Java Pin
427748025-Sep-09 8:25
427748025-Sep-09 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.