473,626 Members | 3,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using PHP to create Excel XML

3 New Member
i am using a php script to generate excel xml. everything works fine as long as the datatype is "String", but nothing quite works right when i switch the datatype to "DateTime". the best i can get is to show a decimal value in the fields i have set to "DateTime", not the standard user-friendly excel display (eg "10:39:00") . i also am trying to write simple formulas to subtract time but have not had any success. the exported excel is useless without these two features and is not any better than a simple tab delimited text file. the whole point of the file is so that someone can view the results online, download the file as an excel spreadsheet, make changes to the data and have the formulas update the totals accordingly. playing with the DateTime format leaves my code looking something like this:

Expand|Select|Wrap|Line Numbers
  1. $tmp = '2007-11-01T12:31:00.000';
  2. $xml .= '                <ss:Cell>
  3.                     <ss:Data ss:Type="DateTime">'.$tmp.'</ss:Data>
  4.                 </ss:Cell>'."\n";
  5.  
i would really like it to just display the time but the excel xml crashes every time i try to make the datatype "Time".

my first crack at the formula looks something like this:

Expand|Select|Wrap|Line Numbers
  1. <Cell ss:Formula="=ABS(C4-C3)+ABS(C2-C1)"/>
but i have a sneaking suspicion i'm going about that all wrong. i've been hunting down tutorials all afternoon and can't seem to find a concise answer to my two problems. any help would be greatly appreciated. i can go into more detail or give further examples if needed. thanks in advance.
Nov 5 '07 #1
4 6125
jkmyoung
2,057 Recognized Expert Top Contributor
How Excel does it when saving to xml:
Declare a style for Time.
Expand|Select|Wrap|Line Numbers
  1. <Style ss:ID="s22">
  2.    <NumberFormat ss:Format="[$-F400]h:mm:ss\ AM/PM"/>
  3. </Style>
Add that style to the cell, eg
Expand|Select|Wrap|Line Numbers
  1. <Cell ss:StyleID="s22"><Data ss:Type="DateTime">2007-11-01T12:31:00.000</Data></Cell>
Nov 6 '07 #2
klb
3 New Member
thanks for the help, that did the trick. now i'm stuck on the formulas part and can't seem to find a good tutorial for writing the formulas i want. my spreadsheet will look something like this:

Expand|Select|Wrap|Line Numbers
  1. Day    In    Out    In    Out    Lunch    Hrs/%    Hrs/Time    Wk Hrs    Wk OT
  2. 1/1/07    7:30am    12:00pm    1:00pm    4:30pm    :45    8.0    8:00        
  3. 1/2/07    8:00am    12:00pm    12:30pm    5:00pm    :30    8.5    8:30        16.00    .5
  4.  
i need to subtract the first "out" from the second "in" and display as time, using a formula so the dates can be changed. i also need to calc the total hours worked per day and per week, and a grand total at the bottom. the kicker is that there could potentially be more clocks than just four in a pay period, so i would have to adjust the forumlas at the time i create the file. i can do this all fine and good in php but am having a little trouble wrapping it up in excel. thanks in advance for any help.
Nov 6 '07 #3
klb
3 New Member
ok, as it turns out i've somewhat figured out how to work formulas, which is a bonus. now my main problems are back to formatting. for the lunch, i need it in H:MM format, and can't seem to get it formatted properly. if i open up the spreadsheet and reformat the decimal values or datetime values that are there, i get the correct result, so i know the formula is doing its job, it's just my formatting that is incorrect. i also need decimal values for total hours worked, eg 8.25 hours for 8:15 hours worked. i've been digging all over the web and can't seem to find a concise answer; if anyone can point me to such a tutorial or reference, i would greatly appreciate it. i'm so close to the end of this project i can taste it!
Nov 7 '07 #4
jkmyoung
2,057 Recognized Expert Top Contributor
Style for short time is like so 10:33
Expand|Select|Wrap|Line Numbers
  1. <Style ss:ID="s24">
  2.  <NumberFormat ss:Format="Short Time"/>
  3. </Style>
Medium time: 10:33 PM
Expand|Select|Wrap|Line Numbers
  1. <Style ss:ID="s25">
  2.  <NumberFormat ss:Format="Medium Time"/>
  3. </Style>
I'm guessing you figured out how to use the relative formulas to calculate the lunch time, eg like: <Cell ss:StyleID="s24 " ss:Formula="=RC[-2]-RC[-3]">

In order to convert hours to decimal format, multiply by 24 (we're counting hours, not days), and set it to the default format, eg like.
Expand|Select|Wrap|Line Numbers
  1. <Style ss:ID="s26">
  2.    <NumberFormat/>
  3. </Style>
Nov 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
5515
by: Jeff | last post by:
I will start off by giving you a background of the process I am taking. The nature of my DTS package is that I recieve an Excel Spreadsheet, run it through the DTS Package applying validation to the records, create an excel file that contians the records that do not pass the validation, send this Excel file back to the person who sent me the original spreadsheet. They will send the Excel Spreadsheet back once they correct the records. ...
4
3393
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property 'Value2'). So I suppose I'm using a incompatible type lib. I'm using Excel 2002 : Excel 10.0 Object Library
9
6597
by: [Yosi] | last post by:
Can I make an Excel file without having Excel in my PC ? I want to create Excel files from my C# application , then open those files later in another PC who have Excel installed . As we can open and read from Access files in C# application without having Access in this PC in this case we install MDAC , Is there any thing similar to MDAC for Excel ? if yes where can I download it ? what is the name of the file ?
4
4518
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a tab delimited file or an excel file. The application then saves the file in the correct format. The flip side is for the user to import/upload the file to the server The application must be able to import the excel file and read the contents. I...
14
5781
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
1
7627
by: Robin Tucker | last post by:
Heres and interesting problem: I have a VB.NET program that creates reports via. Word Automation. This all works fine. What I want to do as part of this report generation process is to embed a graph/chart within the report, once again from VB.NET. I have chosen to use Excel.Chart.8. So, to embed I do this from VB.NET: Dim theNewShape As InlineShape = m_Document.InlineShapes.AddOLEObject (ClassType:="Excel.Chart", _
2
1963
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example, either C# or VB.NET, that I can try. Thank You Very Much,
2
17712
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report from the database but I am not sure how do I put a command button and associate a macro with that using C#. Can anyone help me?? Thanks in advance. Senthil
0
2739
by: liam_jones | last post by:
I'm very new to Python, well IronPython to precise, and have been having problems when using Excel. The problem I'm having is the closing of my Excel object. I'm able to successfully quit the Excel Application that I create, but when I open a Workbook in the Application I can't successfully Quit Excel (by this I mean I can quit it, but the Excel process isn't getting killed and I have to manually go this through Task Manager). I've...
0
2159
by: eolmos | last post by:
Hello everyone, I am currently working on a project that requires a webform in asp.net using C# as the code behind. The page must allow the user to create a report in excel. This report must also generate a chart based on the input dataset. (By the way, the component must be free) So far, I have tried a lot of components which are really good but they do not provide all the required functionality altogether and some of them have trade offs when...
0
8272
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8644
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7206
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6126
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.